Hu et al. in prep. Protistan grazing and biogeography at Gorda Ridge hydrothermal vent field
Code for all data analysis and figure generation, including grazing experiment analysis and sequence data processing. * Import raw counts from FLP disappearance experiments * Perform calculations to estimate grazing pressure * Generate figures to visualize grazing pressure * Import and quality control 18S and 16S tag-sequencing data * Taxonomy curation * Statistical analyses * Figure generation
The following analysis was performed in R version 3.6.1. All input files are available on the Gorda Ridge GitHub.
## ── Attaching packages ────────────────────
## ✓ ggplot2 3.3.1 ✓ purrr 0.3.4
## ✓ tibble 3.0.1 ✓ dplyr 1.0.0
## ✓ tidyr 1.1.0 ✓ stringr 1.4.0
## ✓ readr 1.3.1 ✓ forcats 0.5.0
## ── Conflicts ──── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
##
## Attaching package: 'reshape2'
## The following object is masked from 'package:tidyr':
##
## smiths
##
## ********************************************************
## Note: As of version 1.0.0, cowplot does not change the
## default ggplot2 theme anymore. To recover the previous
## behavior, execute:
## theme_set(theme_cowplot())
## ********************************************************
##
## Attaching package: 'patchwork'
## The following object is masked from 'package:cowplot':
##
## align_plots
# Metadata for each grazing experiment
### Including dive ID, vent/site name, incubation parameters
exp_list <- read.table("data-input/Table1_grazingexp_list.txt",header=T, fill=T, sep="\t")
# head(exp_list)
# Import all cell count information from FLP disappearance experiments
counts <- read.csv("data-input/GordaRidge-cell-count-results.csv")
counts_df <- counts %>%
separate(Site, c("SampleOrigin", "SampleNumber", "Stain"), "-", remove = FALSE) %>%
separate(ID, c("TimePoint", "Bottle", "Replicate"), "-", remove = FALSE) %>%
add_column(excess = "NA108") %>%
unite(Sample.ID, excess, SampleNumber, sep = "-") %>%
data.frame
# head(counts_df[1:3,])
# Import prok counts
prok<-read.table("data-input/prok_counts.txt",header=T, fill=T, sep="\t"); head(prok[1:2,])## Sample_Num Specific_Site Sample.location Prok_count Vent.name
## 1 NA108-036 Plume036 Plume 76899.49 Mt Edwards2
## 2 NA108-013 Mt Edwards Vent 76206.70 Mt Edwards
Sample Plume003, is more appropriately considered near vent bottom water. Modify sample name and entry below.
# head(exp_IDs)
exp_IDs_mod <- exp_list %>%
type.convert(as.is = TRUE) %>%
mutate(Vent.name = case_when(
Sample.ID == "NA108-001" ~ "Near vent BW",
TRUE ~ `Vent.name`),
Sample.Location = case_when(
Sample.ID == "NA108-001" ~ "BW",
TRUE ~ `Sample.Location`)) %>%
mutate(Vent.name = case_when(
Sample.Location == "Plume" ~ "Plume",
TRUE ~ Vent.name))
counts_df_mod <- counts_df %>%
mutate(SampleOrigin = case_when(
Sample.ID == "NA108-001" ~ "BW",
TRUE ~ SampleOrigin)) %>%
select(-Site)
prok_mod <- prok %>%
type.convert(as.is = TRUE) %>%
mutate(Vent.name = case_when(
Specific_Site == "Plume001" ~ "Near vent BW",
TRUE ~ `Vent.name`),
Sample.location = case_when(
Specific_Site == "Plume001" ~ "BW",
TRUE ~ `Sample.location`)) %>%
mutate(Specific_Site = case_when(
Sample.location == "Plume" ~ "Plume",
TRUE ~ Specific_Site),
Vent.name = case_when(
Sample.location == "Plume" ~ "Plume",
TRUE ~ `Vent.name`))# Join count data with experiment IDs so each vent site can be identified by name:
counts_df_ids <- counts_df_mod %>%
left_join(exp_IDs_mod, by = c("SampleOrigin" = "Sample.Location", "Sample.ID" = "Sample.ID")) %>%
unite(Sample, TimePoint, Bottle, sep = "_", remove = FALSE) %>%
data.frame
## View combined table
# head(counts_df_ids) Counts from Vent sample 110 T0 control were repeated three times (3 separate slides). Results are used below as technical replicates to estimate the percentage error rate.
By determining error rate from microscopy counting we can be more confident in evaluating true differences in values.
# Need to determine error rate across technical replicates.
## Prepped a single sample 3 times (3 different days); this was counted separately to to estimate a personal error rate
# This is the % max and min that we will consider to be a margin of error
tech_check <- counts_df_ids %>%
filter(Sample.ID %in% "NA108-110" &
TimePoint %in% "T0" &
Bottle %in% "Ctrl" &
!(Replicate %in% "R2")) %>%
group_by(SampleOrigin, Sample.ID) %>%
summarise(MEAN = mean(Cellsperml), STDEV = sd(Cellsperml), ERR_PER = (100*(STDEV/MEAN))) %>%
data.frame## `summarise()` regrouping output by 'SampleOrigin' (override with `.groups` argument)
# head(tech_check)
PERCENT_ERR <- tech_check[["ERR_PER"]]; PERCENT_ERR # Change in FLP time point to time point must exceed 16%## [1] 16.14934
Get average FLP concentration from T0 experiments and average cells/ml from proj counts
calc_FLP_avg <- counts_df_ids %>%
group_by(SampleOrigin, Sample.ID, T, Bottle, Vent.name, Sample, Stain, T1, T2) %>%
summarise(Avg_cellmL = mean(Cellsperml), # Average cells per ml across replicates
sem=sd(Cellsperml)/sqrt(length(Cellsperml)), # Standard mean error
SD=sd(Cellsperml), #standard deviation
var=sqrt(SD), # variance
Num = n()) %>% #Total number of
data.frame## `summarise()` regrouping output by 'SampleOrigin', 'Sample.ID', 'T', 'Bottle', 'Vent.name', 'Sample', 'Stain', 'T1' (override with `.groups` argument)
# Separate T0 from other time points to calculate % differences in DTAF counts from T0 to T1 and T0 to T2
t0 <- filter(calc_FLP_avg, (T == "T0" & Stain == "DTAF")) %>%
select(-T1, -T2, -Stain, -Num, -T, -Sample, -SD, -var, Avg_cellmL_T0 = Avg_cellmL, sem_T0 = sem) %>%
data.frame
# head(t0)
# Isolate non-T0 time points
t_ex <- filter(calc_FLP_avg, (!(T == "T0") & Stain == "DTAF")) %>%
select(-Stain, -Num, -Sample, -SD, -var) %>%
pivot_wider(names_from = T, values_from = c(Avg_cellmL, sem)) %>%
data.frame
# head(t_ex)
# ?pivot_wider
bac_exp <- calc_FLP_avg %>%
filter(Stain %in% "DAPI") %>%
select(-Bottle, -Stain, -T1, -T2, -SD, -var, -Num, bac_cellmL = Avg_cellmL, bac_sem = sem) %>%
unite(SAMPLE, SampleOrigin, Vent.name, sep = "-", remove = FALSE) %>%
data.frame
# head(bac_exp)
dapi<-as.character(unique(bac_exp$SAMPLE))
# dapi
prok_avg <- prok_mod %>%
group_by(Sample.location, Vent.name) %>%
summarise(prok_avg = mean(Prok_count)) %>%
unite(SAMPLE, Sample.location, Vent.name, sep = "-", remove = FALSE) %>%
data.frame## `summarise()` regrouping output by 'Sample.location' (override with `.groups` argument)
## [1] "SampleOrigin" "Sample.ID" "Bottle" "Vent.name"
## [5] "Avg_cellmL_T0" "sem_T0"
# Calculate percent difference between T0 and T1, and T1 and T2
flp_exp_summary <- t0 %>%
left_join(t_ex) %>%
unite(SAMPLE, SampleOrigin, Vent.name, sep = "-", remove = FALSE) %>%
left_join(prok_avg) %>%
mutate(T0_T1_PercDiff = 100*(abs(Avg_cellmL_T1-Avg_cellmL_T0)/Avg_cellmL_T0),
T0_T2_PercDiff = 100*(abs(Avg_cellmL_T2-Avg_cellmL_T0)/Avg_cellmL_T0)) %>%
data.frame## Joining, by = c("SampleOrigin", "Sample.ID", "Bottle", "Vent.name")
## Joining, by = c("SAMPLE", "Vent.name")
Above data frame created lists the T0 FLP concentration and the T1 and T2 separately. The difference between T0 and T1 or T0 and T2 must exceed the percent error rate to be considered a reliable difference.
# Prep data frame to look at loss of FLP over time for all time points
## Compare to those that exceed error rate
PERCENT_ERR## [1] 16.14934
cells_long <- flp_exp_summary %>%
select(SAMPLE, Bottle, Vent.name, Avg_cellmL_T0, Avg_cellmL_T1, Avg_cellmL_T2, T1, T2) %>%
pivot_longer(cols = starts_with("Avg_cellmL"), names_to = "CountID", values_to = "cellmL") %>%
separate(CountID, c("avg", "excess", "Tx"), sep = "_", remove = FALSE) %>%
select(-avg, -excess) %>%
data.frame
sem_long <- flp_exp_summary %>%
select(SAMPLE, Bottle, Vent.name, sem_T0, sem_T1, sem_T2) %>%
pivot_longer(cols = starts_with("sem"), names_to = "semID", values_to = "sem") %>%
separate(semID, c("excess", "Tx"), sep = "_", remove = FALSE) %>%
select(-excess) %>%
data.frame
# head(cells_long); head(sem_long)
# Combine and fix Timepoint
flp_long_toplot <- cells_long %>%
left_join(sem_long) %>%
select(-semID) %>%
add_column(Hrs = 0) %>%
mutate(Hrs = case_when(
Tx == "T1" ~ T1,
Tx == "T2" ~ T2,
TRUE ~ (as.integer(.$Hrs)))) %>%
select(-T1, -T2) %>%
data.frame## Joining, by = c("SAMPLE", "Bottle", "Vent.name", "Tx")
## Plot average cells/ml for each experiment
# Factor for plotting
sample_order <- c("Near vent BW","Mt Edwards","Venti latte","Candelabra","SirVentsalot")
sample_label <- c("Near vent BW","Mt. Edwards","Venti latte","Candelabra","Sir Ventsalot")
sample_color <-c("#6f88af","#61ac86","#711518","#dfa837","#ce536b")
flp_long_toplot$SAMPLE_ORDER <- factor(flp_long_toplot$Vent.name, levels = (sample_order), labels = sample_label)
names(sample_color) <- sample_label
bottle_order <- c("Ctrl", "Exp")
flp_long_toplot$BOTTLE <- factor(flp_long_toplot$Bottle, levels = bottle_order, labels = c("Control", "Experimental"))# svg("figs/Supplementary-FLP-CTRL-PercError-plot.svg", w = 7, h = 6)
ggplot(flp_long_toplot, aes(x = Hrs, y = cellmL, fill = SAMPLE_ORDER)) +
geom_rect(data = (subset(flp_long_toplot, Tx %in% "T0")), aes(xmin=0, xmax=40,
ymin=(cellmL - ((PERCENT_ERR/100)*cellmL)),
ymax=(cellmL + ((PERCENT_ERR/100)*cellmL))), color=NA,alpha=0.3) +
geom_line(stat = "identity", linetype = 1, aes(group = SAMPLE)) +
geom_errorbar(aes(ymin = (cellmL - sem), ymax = (cellmL + sem)), width = 0.1) +
geom_point(stat = "identity", size = 3, color = "black", aes(fill = SAMPLE_ORDER, shape = SAMPLE_ORDER)) +
scale_y_log10() +
scale_fill_manual(values = sample_color) +
scale_shape_manual(values = c(24,21,21,21,21)) +
labs(y = bquote("FLP cells "~mL^-1), x = "Incubation hours") +
facet_grid(SAMPLE_ORDER~BOTTLE, scales = "free") +
theme_bw() +
theme(panel.grid.minor = element_blank(),
legend.title = element_blank(),
strip.text.x = element_text(face = "bold", color = "black", hjust = 0, size = 10),
strip.text.y = element_text(size = 10),
strip.background = element_blank(),
panel.background = element_blank(),
panel.border = element_blank(),
axis.line = element_line(colour = "black"),
axis.text = element_text(color = "black", size = 9))Subset FLP results to select time points with significant loss in FLP/
# Subset Experiment results and filter for those that exceed the percent error
flp_sig <- flp_exp_summary %>%
filter(Bottle %in% "Exp") %>%
select(-T1, -T2) %>%
mutate(T1_sig = case_when(
T0_T1_PercDiff > PERCENT_ERR ~ "exceeds"),
T2_sig = case_when(T0_T2_PercDiff > PERCENT_ERR ~ "exceeds")
) %>%
data.frame
# head(flp_sig)
# Select experiments that T1 exceeds percent difference
T1_tmp <- flp_sig %>%
filter(T1_sig == "exceeds") %>%
select(SAMPLE) %>%
data.frame
T1_tmp$Tx = "T1"
T1_tmp$Keep = "yes"
# Select experiments that T1 was NA, but T2 was significant
T2_tmp <- flp_sig %>%
filter(is.na(T1_sig) & T2_sig == "exceeds") %>%
select(SAMPLE) %>%
data.frame
T2_tmp$Tx = "T2"
T2_tmp$Keep = "yes"
keep_status <- rbind(T1_tmp, T2_tmp); #keep_status
# # KEPT:
# # near vent point T2, Candelabra T2
# # Mt Edwards time point T1, Sirventsalot T1, & venti latte T1# Join experiments that are significant and filter data to keep.
t <- c("T1", "T2")
flp_trend_sig <- flp_long_toplot %>%
filter(Bottle == "Exp") %>%
left_join(keep_status) %>%
filter(Tx == "T0" | (Tx %in% t & Keep == "yes")) %>%
separate(SAMPLE, c("SampleOrigin", "excess"), sep = "-", remove = FALSE) %>%
select(-Keep, -excess) %>%
data.frame## Joining, by = c("SAMPLE", "Tx")
These values are used for all downstream grazing rate calculations, as the loss in FLP was found to exceed the microscopy count error percentage.
# Factor for plotting
## use characterise lists from above
flp_trend_sig$SAMPLE_ORDER <- factor(flp_trend_sig$Vent.name, levels = (sample_order), labels = sample_label)
plot_graze_trends <- ggplot(flp_trend_sig,
aes(x = Hrs, y = cellmL, fill = SAMPLE_ORDER, shape = SampleOrigin)) +
geom_line(stat="identity", aes(group = SAMPLE_ORDER, linetype = SampleOrigin)) +
geom_errorbar(aes(ymin = (cellmL-sem), ymax = (cellmL+sem)), size = 0.5, width = 0.1)+
geom_point(stat="identity", size=3, color="black") +
scale_linetype_manual(values = c(1, 1))+
scale_fill_manual(values = sample_color)+
scale_shape_manual(values = c(23,21))+
scale_y_log10(limits = c(5e3,1e5))+
labs(y = bquote("FLP cells "~mL^-1), x = "Incubation hours")+
theme_minimal()+
theme(panel.grid.major = element_line(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"),
axis.text=element_text(color="black"),
legend.title = element_blank()) +
guides(fill = guide_legend(override.aes = list(shape = c(23,21,21,21,21))),
shape = guide_legend(override.aes = list(fill = "black"))) +
annotation_logticks(sides = "l")
# plot_graze_trendsConsistent loss in FLP over time
processed_data <- flp_trend_sig %>%
type.convert(as.is = TRUE) %>%
mutate(TimePoint = case_when(Tx == "T0" ~ "T0",
Tx != "T0" ~ "Tf")) %>%
select(-Tx, -CountID) %>%
pivot_wider(names_from = TimePoint, values_from = c(cellmL, sem, Hrs)) %>%
select(-Hrs_T0) %>%
left_join(prok_avg) %>%
data.frame## Joining, by = c("SAMPLE", "Vent.name")
Grazing rate calculation from Connell et al. 2017 mortality factor = ln(Tf/T0) * (-1/t) t = incubation hours reported as days Tf = number of FLP at end of experiment T0 = number of FLP at beginning of experiment The natural log in R is ‘log()’
# cellmL = prokaryote average cells per ml
graze_rate <- processed_data %>%
# type.convert(as.is = TRUE) %>%
group_by(SAMPLE, SampleOrigin, Vent.name, Hrs_Tf, SAMPLE_ORDER) %>%
mutate(
# Calculate mortality factor (m)
MORTALITY = (log(cellmL_Tf/cellmL_T0))*(-1/(Hrs_Tf/24)),
MORTALITY_min = (log((cellmL_Tf-sem_Tf)/(cellmL_T0-sem_T0)))*(-1/(Hrs_Tf/24)),
MORTALITY_max = (log((cellmL_Tf+sem_Tf)/(cellmL_T0+sem_T0)))*(-1/(Hrs_Tf/24)),
# Calculate model I G - Rate over given amount of time
G = ((cellmL_T0 - cellmL_Tf) * (prok_avg / cellmL_T0)),
G_min = (((cellmL_T0-sem_T0) - (cellmL_Tf-sem_Tf)) * (prok_avg / (cellmL_T0-sem_T0))),
G_max = (((cellmL_T0+sem_T0) - (cellmL_Tf+sem_Tf)) * (prok_avg / (cellmL_T0+sem_T0))),
# Calculate Grazing per hour
GrazingRate_hr = (G/Hrs_Tf),
GrazingRate_hr_min = (G_min/Hrs_Tf),
GrazingRate_hr_max = (G_max/Hrs_Tf),
# Estimate prokaryote turnover % per day
Prok_turnover = (100*(G / prok_avg)), #Convert to per day (*24)
Prok_turnover_min = (100*(G_min / prok_avg)),
Prok_turnover_max = (100*(G_max / prok_avg)),
# Prok_turnover = (100*((rate * cellmL)/cellmL)), #ARCHIVE
# Prok_turnover_min = (100*((rate_min * cellmL)/cellmL)), #ARCHIVE
# Prok_turnover_max = (100*((rate_max * cellmL)/cellmL)) #ARCHIVE
# Model II
N_avg = ((prok_avg + prok_avg)/2),
F_avg = ((cellmL_T0 + cellmL_Tf)/2),
q = ((cellmL_T0 - cellmL_Tf)/F_avg),
# G_II a and b should be equivalent
G_II_a = q * (N_avg),
G_II_b = ((cellmL_T0 - cellmL_Tf) * ((prok_avg+prok_avg)/(cellmL_T0+cellmL_Tf))),
GrazingRate_hr_II = (G_II_a/Hrs_Tf)
) %>%
data.frame# Factor for plotting
sample_order <- c("Near vent BW","Mt Edwards","Venti latte","Candelabra","SirVentsalot")
sample_label <- c("Near vent BW","Mt. Edwards","Venti latte","Candelabra","Sir Ventsalot")
sample_color <-c("#6f88af","#61ac86","#711518","#dfa837","#ce536b")
graze_rate$SAMPLE_ORDER <- factor(graze_rate$Vent.name, levels = rev(sample_order), labels = rev(sample_label))
mortality <- ggplot(graze_rate, aes(x = SAMPLE_ORDER, y = GrazingRate_hr, fill = SAMPLE_ORDER, shape = SampleOrigin)) +
geom_errorbar(aes(ymin = GrazingRate_hr_min, ymax = GrazingRate_hr_max), size = 0.5, width = 0.1) +
geom_point(stat = "identity", size = 3, color = "black", aes(shape = SampleOrigin)) +
scale_fill_manual(values = rev(sample_color)) +
scale_shape_manual(values = c(23,21)) +
coord_flip() +
labs(x = "", y = bquote("Cells "~mL^-1 ~consumed ~hr^-1)) +
theme_minimal() +
theme(panel.grid.major = element_line(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"),
axis.text=element_text(color="black"), axis.ticks = element_line(),
legend.position = "none", strip.text =element_blank())
# mortalitybar_plot <- ggplot(graze_rate, aes(x = SAMPLE_ORDER, y = Prok_turnover)) +
geom_bar(stat = "identity", position = "stack", width = 0.6, aes(fill = SAMPLE_ORDER)) +
geom_errorbar(aes(ymin = Prok_turnover_min, ymax = Prok_turnover_max), size = 0.5, width = 0.1) +
scale_fill_manual(values = rev(sample_color)) +
scale_y_continuous(expand = c(0,0), limits = c(0,100)) +
labs(x = "", y = bquote("Prokaryote turnover %"~d^-1)) +
coord_flip() +
theme_minimal() +
theme(panel.grid.major = element_line(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"),
axis.text=element_text(color="black"), axis.ticks = element_line(),
legend.position = "none", strip.text =element_blank())
# bar_plotleg <- get_legend(plot_graze_trends)
# svg("figs/Grazing-results-panel-03-11-2020.svg", h = 3, w = 12)
plot_grid(plot_graze_trends + theme(legend.position = "none"),
mortality + theme(axis.text.y = element_blank()) + labs(x = "Grazing experiment"),
bar_plot + theme(axis.text.y = element_blank()), leg,
axis = c("tblr"), labels = c("a", "b", "c", ""), nrow = 1)# Replace with the calcs to place into context with McNichol et al. work
# head(graze_rate)
# G = number of cells grazed during experiment duration
graze_rate_wCarbon <- graze_rate %>%
add_column(fgC_cell_morono = 86) %>% # Add in Morono et al. 2011 value
add_column(fgC_cell_mcnic = 173) %>%
mutate(
cells_consumed_perday = (G / (Hrs_Tf /24)), # Rate of cells consumed * in situ prok, per day (day = hours of incubation reported in days)
fgC_ml_perday_morono = (cells_consumed_perday * fgC_cell_morono),
fgC_ml_perday_mcnic = (cells_consumed_perday * fgC_cell_mcnic),# Convert cell amount to fg C
ugC_L_perday_morono = (fgC_ml_perday_morono * (1e-09) * 1000), # Convert to ug C per L
ugC_L_perday_mcnic = (fgC_ml_perday_mcnic * (1e-09) * 1000),
lower_mcnichol_morono = 100*(ugC_L_perday_morono / 17.3),
upper_mcnichol_morono = 100*(ugC_L_perday_morono / 321.4),
lower_mcnichol_mcnic = 100*(ugC_L_perday_mcnic / 17.3),
upper_mcnichol_mcnic = 100*(ugC_L_perday_mcnic / 321.4)
) %>%
data.frame
# head(graze_rate_wCarbon)
# View(graze_rate_wCarbon)
# write_delim(graze_rate_wCarbon, path = "Grazing-calc-wCarbon-results.txt", delim = "\t")# carbon_density <- crossing(fgC_cell = seq(86, 300, by = 1),
# GrazingRate_hr = seq(min(graze_rate$GrazingRate_hr), max(graze_rate$GrazingRate_hr), length.out = 215)) %>%
# mutate(fgC_ml_perday = ((GrazingRate_hr*24) * fgC_cell),
# ugC_L_perday = (fgC_ml_perday * (1e-09) * 1000)
# ) %>%
# data.frame
# head(carbon_density)
# dim(carbon_density)
# min(graze_rate$G)
# max(graze_rate$G)# ten <- carbon_density %>% filter(ugC_L_perday > 10 & ugC_L_perday < 10.01)
# five <- carbon_density %>% filter(ugC_L_perday > 5 & ugC_L_perday < 5.01)
# two <- carbon_density %>% filter(ugC_L_perday > 2 & ugC_L_perday < 2.01)
# # range(carbon_density$ugC_L_perday)
# # str(carbon_density)
# # pdf("figs/Raster-carbon.pdf", w = 5, h = 3.5)
# ggplot(carbon_density, aes(x = fgC_cell, y = GrazingRate_hr)) +
# geom_raster(aes(fill = ugC_L_perday)) +
# scale_fill_gradientn(colors = c("#fef0d9", "#b30000"), name = bquote("ug C"~L^-1 ~day^-1)) +
# # scale_fill_discrete(name = "New Legend Title")
# scale_y_continuous(expand = c(0,0)) +
# scale_x_continuous(expand = c(0,0)) +
# theme_bw() +
# theme(axis.text = element_text(color = "black"),
# rect = element_rect(fill = "transparent"),
# panel.background = element_rect(fill = "transparent"),
# plot.background = element_rect(fill = "transparent", color = NA)) +
# labs(y = bquote("Cells "~mL^-1 ~consumed ~hr^-1), x = bquote("fg C"~cell^-1)) +
# geom_line(data = ten,
# aes(x = fgC_cell,
# y = GrazingRate_hr), color = "white", size = 0.2) +
# geom_line(data = five,
# aes(x = fgC_cell,
# y = GrazingRate_hr), color = "white", size = 0.2) +
# geom_line(data = two,
# aes(x = fgC_cell,
# y = GrazingRate_hr), color = "white", size = 0.2) +
# geom_point(x = 87, y = (255.3789), shape = 23, color = "#6f88af", fill = "#6f88af") +
# geom_point(x = 87, y = (700.7713), shape = 21, color = "#61ac86", fill = "#61ac86") +
# geom_point(x = 87, y = (1646.7899), shape = 21, color = "#711518", fill = "#711518") +
# geom_point(x = 87, y = (902.8954), shape = 21, color = "#dfa837", fill = "#dfa837") +
# geom_point(x = 87, y = (1828), shape = 21, color = "#ce536b", fill = "#ce536b")
# dev.off()x <- as.character(unique(flp_long_toplot$Vent.name))
# x
prok_avg_mod <- prok_avg %>%
add_column(BOTTLE = "in situ") %>%
select(SAMPLE, Vent.name, BOTTLE, cellmL = prok_avg) %>%
filter(Vent.name %in% x) %>%
data.frame
# head(prok_avg_mod)t0_flp <- flp_long_toplot %>%
filter(Tx == "T0") %>%
select(SAMPLE, Vent.name, BOTTLE, cellmL) %>%
data.frame
# t0_flp
# head(t0_flp)
# Combine
t0_insitu_counts <- rbind(t0_flp, prok_avg_mod) #; t0_insitu_counts# svg("flp-insitu-prok-counts.svg", w = 6, h = 5)
# ggplot(t0_insitu_counts, aes(x = Vent.name, y = cellmL, fill = BOTTLE, shape = BOTTLE)) +
# geom_point(stat = "identity", size = 4) +
# scale_y_log10(limits = c(1e3,1e6)) +
# scale_fill_manual(values = c("#d73027", "#fee090", "#4575b4")) +
# scale_shape_manual(values = c(22, 22, 23)) +
# labs(x = "", y = "cells/mL") +
# theme_bw() +
# theme(legend.title = element_blank(),
# axis.text.x = element_text(angle = 90, color = "black", size = 12, hjust = 1, vjust = 0.5),
# axis.text.y = element_text(color = "black", size = 12))
# dev.off()Set up working R environment and import 18S ASV table. Modify input tables and import as phyloseq objects in order to perform quality control removal of contaminant ASVs (decontam).
## Loading objects:
## GR_tagseq_longformat
## GR_tagseq_wideformat
Import ASV table as phyloseq object, note control samples.
taxmat <- GR_tagseq_wideformat %>%
select(Feature.ID, Taxon_updated) %>%
separate(Taxon_updated, c("Kingdom","Supergroup","Division","Class","Order","Family","Genus","Species"), sep = ";", remove = FALSE) %>%
column_to_rownames(var = "Feature.ID") %>%
as.matrix## Warning: Expected 8 pieces. Missing pieces filled with `NA` in 4828 rows [3, 5,
## 9, 11, 14, 20, 23, 28, 33, 34, 35, 37, 39, 40, 44, 46, 47, 53, 55, 57, ...].
Note that Axial ID originates from a laboratory blank sample that was exactrated at the same time.
asvmat <- GR_tagseq_wideformat %>%
select(Feature.ID, starts_with(c("Gorda", "Axial"))) %>%
column_to_rownames(var = "Feature.ID") %>%
as.matrixImport metadata below and combine with phyloseq object.
row.names(taxmat)<-row.names(asvmat)
# class(asvmat);class(taxmat)
ASV = otu_table(asvmat, taxa_are_rows = TRUE) #phyloseq command
TAX = tax_table(taxmat)
physeq <- phyloseq(ASV, TAX)
physeq #Phyloseq object## phyloseq-class experiment-level object
## otu_table() OTU Table: [ 9175 taxa and 34 samples ]
## tax_table() Taxonomy Table: [ 9175 taxa by 9 taxonomic ranks ]
# Include additional sample names
samplenames <- as.data.frame(colnames(asvmat))
# samplenames; head(asvtab)
colnames(samplenames)[1]<-"SAMPLE"
# Import metadata
ventnames <- read.delim("data-input/ventnames-gordaridge.txt")
# names(ventnames);head(ventnames)
# View(ventnames)
colnames(ventnames)[1]<-"SAMPLE"
ventnames## SAMPLE LOCATION LOCATION_SPECIFIC
## 1 Axial_ExtractControl_CTRL_2019 ExtractControl ExtractControl
## 2 GordaRidge_Plume001_T0_2019_REP12 GordaRidge Plume001
## 3 GordaRidge_Plume001_T24_2019_REP12 GordaRidge Plume001
## 4 GordaRidge_Plume001_T36_2019_REP12 GordaRidge Plume001
## 5 GordaRidge_Vent013_T0_2019_REP13 GordaRidge Vent013
## 6 GordaRidge_Vent013_T36_2019_REP12 GordaRidge Vent013
## 7 GordaRidge_Vent013_T36_2019_REP34 GordaRidge Vent013
## 8 GordaRidge_Vent043_T0_2019_REP13 GordaRidge Vent043
## 9 GordaRidge_Vent043_T36_2019_REP13 GordaRidge Vent043
## 10 GordaRidge_Vent110_T24_2019 GordaRidge Vent110
## 11 GordaRidge_Vent090_T24_2019 GordaRidge Vent090
## 12 GordaRidge_Plume001_T0_2019_REP34 GordaRidge Plume001
## 13 GordaRidge_Plume001_sterivex_2019_REPa GordaRidge Plume001
## 14 GordaRidge_Plume001_sterivex_2019_REPb GordaRidge Plume001
## 15 GordaRidge_Shipblank_CTRL_2019_S31 GordaRidge Shipblank
## 16 GordaRidge_Shipblank_CTRL_2019_S32 GordaRidge Shipblank
## 17 GordaRidge_Shipblank_CTRL_2019_S33 GordaRidge Shipblank
## 18 GordaRidge_BSW020_sterivex_2019_REPa GordaRidge BSW020
## 19 GordaRidge_Plume036_sterivex_2019_REPb GordaRidge Plume036
## 20 GordaRidge_BSW056_sterivex_2019_REPb GordaRidge BSW056
## 21 GordaRidge_BSW081_sterivex_2019 GordaRidge BSW081
## 22 GordaRidge_Plume096_sterivex_2019 GordaRidge Plume096
## 23 GordaRidge_Vent009_SUPRS1_2019 GordaRidge Vent009
## 24 GordaRidge_Vent039_SUPRS1_2019 GordaRidge Vent039
## 25 GordaRidge_Vent086_SUPRS1_2019 GordaRidge Vent086
## 26 GordaRidge_Vent105_SUPRS9_2019 GordaRidge Vent105
## 27 GordaRidge_Vent010_SUPRS2_2019 GordaRidge Vent010
## 28 GordaRidge_Vent011_SUPRS3_2019 GordaRidge Vent011
## 29 GordaRidge_Vent040_SUPRS2_2019 GordaRidge Vent040
## 30 GordaRidge_Vent041_SUPRS3_2019 GordaRidge Vent041
## 31 GordaRidge_Vent087_SUPRS2_2019 GordaRidge Vent087
## 32 GordaRidge_Vent088_SUPRS3_2019 GordaRidge Vent088
## 33 GordaRidge_Vent106_SUPRS10_2019 GordaRidge Vent106
## 34 GordaRidge_Vent107_SUPRS11_2019 GordaRidge Vent107
## SAMPLEID Sampletype LocationName Sample_or_Control Sample_or_BSW
## 1 CTRL Control Lab blank Control Sample Control
## 2 T0 Grazing Near vent BW True Sample True Sample
## 3 T24 Grazing Near vent BW True Sample True Sample
## 4 T36 Grazing Near vent BW True Sample True Sample
## 5 T0 Grazing Mt Edwards Vent True Sample True Sample
## 6 T36 Grazing Mt Edwards Vent True Sample True Sample
## 7 T36 Grazing Mt Edwards Vent True Sample True Sample
## 8 T0 Grazing Venti Latte Vent True Sample True Sample
## 9 T36 Grazing Venti Latte Vent True Sample True Sample
## 10 T24 Grazing SirVentsAlot Vent True Sample True Sample
## 11 T24 Grazing Candelabra Vent True Sample True Sample
## 12 T0 Grazing Near vent BW True Sample True Sample
## 13 sterivex in situ Near vent BW True Sample True Sample
## 14 sterivex in situ Near vent BW True Sample True Sample
## 15 CTRL control Shipblank Control Sample Control
## 16 CTRL control Shipblank Control Sample Control
## 17 CTRL control Shipblank Control Sample Control
## 18 sterivex in situ Deep seawater True Sample BSW
## 19 sterivex in situ Plume True Sample True Sample
## 20 sterivex in situ Deep seawater True Sample BSW
## 21 sterivex in situ Shallow seawater True Sample BSW
## 22 sterivex in situ Plume True Sample True Sample
## 23 SUPRS1 in situ Mt Edwards Vent True Sample True Sample
## 24 SUPRS1 in situ Venti Latte Vent True Sample True Sample
## 25 SUPRS1 in situ Candelabra Vent True Sample True Sample
## 26 SUPRS9 in situ SirVentsAlot Vent True Sample True Sample
## 27 SUPRS2 in situ Mt Edwards Vent True Sample True Sample
## 28 SUPRS3 in situ Mt Edwards Vent True Sample True Sample
## 29 SUPRS2 in situ Venti Latte Vent True Sample True Sample
## 30 SUPRS3 in situ Venti Latte Vent True Sample True Sample
## 31 SUPRS2 in situ Candelabra Vent True Sample True Sample
## 32 SUPRS3 in situ Candelabra Vent True Sample True Sample
## 33 SUPRS10 in situ SirVentsAlot Vent True Sample True Sample
## 34 SUPRS11 in situ SirVentsAlot Vent True Sample True Sample
## Joining, by = "SAMPLE"
row.names(samplenames_1)<-sample_names(physeq)
samplenames_1 <- samplenames_1 %>% unite(LocationName_Sampletype, LocationName, Sampletype, sep = " ", remove = FALSE)
# Convert to phyloseq object
sampledata <- sample_data(samplenames_1)
# Merge with other data
physeq_names = merge_phyloseq(physeq, sampledata)
# physeq_names
# sample_data(physeq_names)Decontam will identify putative contaminate ASVs based on the difference in prevalence between control blank and environmental samples. First review the library size or number of sequences within each sample to see how varied the control samples are to the experimental samples.
## phyloseq-class experiment-level object
## otu_table() OTU Table: [ 9175 taxa and 34 samples ]
## sample_data() Sample Data: [ 34 samples by 9 sample variables ]
## tax_table() Taxonomy Table: [ 9175 taxa by 9 taxonomic ranks ]
# Check out library size of my data
df <- as.data.frame(sample_data(physeq_names))
df$LibrarySize <- sample_sums(physeq_names)
df <- df[order(df$LibrarySize),]
df$Index <- seq(nrow(df))
#
ggplot(data=df, aes(x=Index, y=LibrarySize, fill=Sample_or_Control, shape=LOCATION)) +
geom_point(color="black", size=3, aes(shape=LOCATION)) +
scale_shape_manual(values = c(21,22,23)) +
theme_bw() > Shows that out of the 3 ship blanks I have, one of the sames has a pretty large library size, otherwise, control samples have very small library sizes.
# Assign negative control designation
sample_data(physeq_names)$is.neg <- sample_data(physeq_names)$Sample_or_Control == "Control Sample"
# ID contaminants using Prevalence information
contamdf.prev <- isContaminant(physeq_names, method="prevalence", neg="is.neg", threshold = 0.5, normalize = TRUE)
table(contamdf.prev$contaminant) # Report number of ASVs IDed as contamintants##
## FALSE TRUE
## 9141 34
0.5 - this threshold will ID contaminants in all samples that are more prevalent in negative controls than in positive samples. In this study, control samples included 1 lab-based blank and 3 ship-board blanks taken at the time of field study. Results showed 34 ASVs to be considered “contaminants”
# Make phyloseq object of presence-absence in negative controls and true samples
## change to presence absence
gr.pa <- transform_sample_counts(physeq_names, function(abund) 1*(abund>0))
# isolate PA of positive and negative samples
gr.pa.neg <- prune_samples(sample_data(gr.pa)$Sample_or_Control == "Control Sample", gr.pa)
gr.pa.pos <- prune_samples(sample_data(gr.pa)$Sample_or_Control == "True Sample", gr.pa)# Subset TRUE contaminants
contams <- subset(contamdf.prev, contaminant == "TRUE")
contams$Feature.ID <- row.names(contams)
# head(contams);dim(contams)
list_of_contams <- as.character(contams$Feature.ID)
#
# Explore taxa IDed as contaminants
taxa_list <- as.data.frame(taxmat)
taxa_list$Feature.ID <- row.names(taxa_list)
taxa_contams <- left_join(contams, taxa_list)
# write_delim(taxa_contams, path = "List-of-contaminant-ASVs.txt", delim = "\t")
# Plot total sequences and which are contaminants
# Remove contaminant and count sequence sums per sample to see which samples had the highest number of contamiant sequences removed.
# After remove contaminants, what % of sequences is removed?
# head(GR_tagseq_counts[1:2,])
GR_tagseq_longformat$CONTAM <- "Pass"
# head(contams[1:2,])
# str(list_of_contams)
GR_tagseq_longformat$CONTAM[GR_tagseq_longformat$Feature.ID %in% list_of_contams] = "Fail"
# head(GR_tagseq_counts[1:2,])
# Make character list of all feature.ids to KEEP:
keep1<- subset(GR_tagseq_longformat, CONTAM %in% "Pass")
# length(unique(keep1$Feature.ID))
keep_asvs <- as.character(unique(keep1$Feature.ID)) #see below
#
passfail <- GR_tagseq_longformat %>%
group_by(SAMPLE, CONTAM) %>%
summarise(SUM_CONTAM = sum(COUNT)) %>%
data.frame## [1] 1569829
## [1] 9175
# unique(GR_tagseq_counts$SAMPLEID)
GR_tagseq_counts_noCTRL <- subset(GR_tagseq_longformat, !(SAMPLEID %in% "CTRL"))
# New total number of sequences
sum(GR_tagseq_counts_noCTRL$COUNT)## [1] 1479273
counts_decont <- subset(GR_tagseq_longformat, !(Feature.ID %in% list_of_contams))
length(unique(counts_decont$Feature.ID)) - length(unique(GR_tagseq_longformat$Feature.ID)) # Confirm 34 lines removed## [1] -34
# % of sequences was removed following decontam; this is counting the ship blank samples themselves
100*(1-(sum(counts_decont$COUNT)/sum(GR_tagseq_counts_noCTRL$COUNT)))## [1] 1.23581
## Using SUM_CONTAM as value column: use value.var to override.
passfail_wide$PercLossSeq <- paste(100*(passfail_wide$Fail/(passfail_wide$Fail+passfail_wide$Pass)))
# dim(passfail_wide)
# write.csv(passfail_wide, file="PercSeqLost-decontam.csv")
# breakdown by sample - reports % lost per sample
# Remove contaminant sequences from phyloseq object:
# Subset TRUE contaminants
# ?prune_taxa
# class(keep_asvs)
physeq_tmp <- prune_taxa(keep_asvs, physeq_names)
# sample_data(physeq_tmp)
# Remove one sample with too few sequences
physeq_clean <- subset_samples(physeq_tmp, sample_names(physeq_tmp) !="GordaRidge_BSW020_sterivex_2019_REPa")
# sample_data(physeq_clean)
# physeq_clean
# Remove control samples from data frame
tmp <- subset(GR_tagseq_longformat, !(SAMPLEID %in% "CTRL")) # Remove controls, get list of sample names that are controls
samples_keep <- as.character(unique(tmp$SAMPLE))
physeq_clean_true <- prune_samples(samples_keep, physeq_clean)Import cleaned ASV data, curate taxonomic assignments specific to protists, create bar plot to demonstrate protistan diversity at Gorda Ridge.
## Loading objects:
## counts_decont
gr_counts <- counts_decont %>%
filter(COUNT > 0) %>%
separate(Taxon_updated, c("Kingdom","Supergroup","Division","Class","Order","Family","Genus","Species"), sep = ";", remove = FALSE) %>%
data.frame
# head(gr_counts)
tax_only_tmp <- gr_counts %>%
select(Taxon_updated, Kingdom,Supergroup,Division,Class,Order,Family,Genus,Species) %>%
distinct() %>%
data.frameventnames <- read.delim("data-input/ventnames-gordaridge.txt")
colnames(ventnames)[1]<-"SAMPLE"
# Join with dataframe
gr_counts_name <- gr_counts %>%
left_join(select(ventnames, SAMPLE, LOCATION_SPECIFIC, Sampletype, LocationName)) %>%
data.frame## Joining, by = "SAMPLE"
Function below pr2_curate() is the custom manual curation of the taxonomic assignments from the PR2 database. The function creates new columns with taxonomic information that summarizes the core groups in the dataset.
pr2_curate <- function(df){
# Add a column
df$Taxa <-"Unassigned-Eukaryote"
df$Taxa[df$Supergroup == "Alveolata"]="Alveolata-Other"
df$Taxa[df$Division == "Ciliophora"]="Alveolata-Ciliates"
df$Taxa[df$Division == "Dinoflagellata"]="Alveolata-Dinoflagellates"
df$Taxa[df$Class == "Syndiniales"] = "Alveolata-Syndiniales"
df$Taxa[df$Class == "Apicomplexa"]="Alveolata-Apicomplexa"
df$Taxa[df$Supergroup == "Hacrobia"]="Hacrobia-Other"
df$Taxa[df$Division == "Cryptophyta"]="Hacrobia-Cryptophyta"
df$Taxa[df$Division == "Haptophyta"]="Hacrobia-Haptophyta"
df$Taxa[df$Supergroup == "Opisthokonta"]="Opisthokonta-Other"
df$Taxa[df$Division == "Fungi"]="Opisthokonta-Fungi"
df$Taxa[df$Division == "Metazoa"]="Opisthokonta-Metazoa"
df$Taxa[df$Supergroup == "Stramenopiles"]="Stramenopiles-Other"
df$Taxa[df$Class == "Bicoecea"]="Stramenopiles-Bicoecea"
df$Taxa[df$Division == "Ochrophyta"]="Stramenopiles-Ochrophyta"
mast <- unique(filter(df, grepl("MAST", Class)) %>% select(Class))
mast_list <- as.character(mast$Class)
df$Taxa[df$Class %in% mast_list]="Stramenopiles-MAST"
df$Taxa[df$Supergroup == "Archaeplastida"]="Archaeplastida-Other"
df$Taxa[df$Division == "Chlorophyta"]="Archaeplastida-Chlorophyta"
df$Taxa[df$Supergroup == "Excavata"]="Excavata"
df$Taxa[df$Supergroup == "Apusozoa"]="Apusozoa"
df$Taxa[df$Supergroup == "Amoebozoa"]="Amoebozoa"
df$Taxa[df$Supergroup == "Rhizaria"]="Rhizaria-Other"
df$Taxa[df$Division == "Cercozoa"]="Rhizaria-Cercozoa"
df$Taxa[df$Division == "Radiolaria"]="Rhizaria-Radiolaria"
return(df)
}Apply PR2 curation to 18S data.
gr_counts_wtax <- pr2_curate(gr_counts_name)
# head(gr_counts_wtax[1:3,])
unique(gr_counts_wtax$Taxa)## [1] "Alveolata-Ciliates" "Unassigned-Eukaryote"
## [3] "Opisthokonta-Metazoa" "Archaeplastida-Other"
## [5] "Opisthokonta-Fungi" "Stramenopiles-MAST"
## [7] "Stramenopiles-Ochrophyta" "Alveolata-Dinoflagellates"
## [9] "Alveolata-Syndiniales" "Rhizaria-Radiolaria"
## [11] "Hacrobia-Haptophyta" "Opisthokonta-Other"
## [13] "Archaeplastida-Chlorophyta" "Rhizaria-Cercozoa"
## [15] "Amoebozoa" "Hacrobia-Other"
## [17] "Stramenopiles-Other" "Hacrobia-Cryptophyta"
## [19] "Alveolata-Other" "Apusozoa"
## [21] "Stramenopiles-Bicoecea" "Rhizaria-Other"
## [23] "Excavata"
Output is the full ASV table with added columns for curated taxonomy. Above also provides a list of the unique taxonomic names assigned.
gr_counts_wtax_samplesonly <- subset(gr_counts_wtax, !(Sampletype == "control"))
## To average across replicates, modify SUPR sample names
gr_counts_filter <- gr_counts_wtax_samplesonly
gr_counts_filter$SAMPLEID<- sub("SUPRS9", "SUPR", gr_counts_filter$SAMPLEID)
gr_counts_filter$SAMPLEID<- sub("SUPRS11", "SUPR", gr_counts_filter$SAMPLEID)
gr_counts_filter$SAMPLEID<- sub("SUPRS10", "SUPR", gr_counts_filter$SAMPLEID)
gr_counts_filter$SAMPLEID<- sub("SUPRS2", "SUPR", gr_counts_filter$SAMPLEID)
gr_counts_filter$SAMPLEID<- sub("SUPRS3", "SUPR", gr_counts_filter$SAMPLEID)
gr_counts_filter$SAMPLEID<- sub("SUPRS1", "SUPR", gr_counts_filter$SAMPLEID)# Sum of all sequences
a <- sum(gr_counts_filter %>% filter(!(SAMPLEID == "CTRL")) %>% select(COUNT)); a## [1] 1434482
# Total ASVs
dim(unique(gr_counts_filter %>% filter(!(SAMPLEID == "CTRL")) %>% select(Feature.ID)))[1]## [1] 9028
# Percentage of all sequences Unassigned Eukaryote
x <- sum(gr_counts_filter %>% filter(!(SAMPLEID == "CTRL")) %>% filter(Taxon_updated == "Eukaryota") %>% select(COUNT))
100*(x/a)## [1] 2.823876
# Total ASVs left "Unassigned-Eukaryote"
dim(unique(gr_counts_filter %>% filter(!(SAMPLEID == "CTRL")) %>% filter(Taxon_updated == "Eukaryota") %>% select(Feature.ID)))[1]## [1] 1058
# Percentage of all sequences assigned Opisthokonts
x <- sum(gr_counts_filter %>% filter(!(SAMPLEID == "CTRL")) %>% filter(Supergroup == "Opisthokonta") %>% select(COUNT))
100*(x/a)## [1] 12.92606
dim(unique(gr_counts_filter %>% filter(!(SAMPLEID == "CTRL")) %>% filter(Supergroup == "Opisthokonta") %>% select(Feature.ID)))[1]## [1] 615
Average ASV sequence counts across replicate samples, COUNT_AVG column will now equal the ASV sequence count value across replicates
gr_counts_avg_wtax <- gr_counts_filter %>%
mutate(LocationName = case_when(
LOCATION_SPECIFIC == "Plume036" ~ "Candelabra Plume",
LOCATION_SPECIFIC == "Plume096" ~ "Mt Edwards Plume",
TRUE ~ as.character(LocationName)
)) %>%
group_by(Feature.ID, SAMPLEID, Sampletype, LOCATION_SPECIFIC, LocationName, Taxon_updated, Kingdom, Supergroup, Division, Class, Order, Family, Genus, Species, Taxa) %>%
summarise(COUNT_AVG = mean(COUNT)) %>%
as.data.frame
# dim(gr_counts_filter);dim(gr_counts_avg_wtax)
# tmp <- gr_counts_avg_wtax %>% select(Taxa, Taxon_updated, Kingdom, Supergroup, Division, Class, Order, Family, Genus, Species) %>% distinct() %>% data.frame
# write_delim(tmp, path = "tax-tmp-2.txt", delim = "\t")
unique(gr_counts_avg_wtax$Taxa)## [1] "Rhizaria-Radiolaria" "Stramenopiles-MAST"
## [3] "Opisthokonta-Metazoa" "Alveolata-Ciliates"
## [5] "Alveolata-Syndiniales" "Stramenopiles-Ochrophyta"
## [7] "Stramenopiles-Other" "Alveolata-Dinoflagellates"
## [9] "Unassigned-Eukaryote" "Rhizaria-Cercozoa"
## [11] "Opisthokonta-Other" "Hacrobia-Haptophyta"
## [13] "Alveolata-Other" "Stramenopiles-Bicoecea"
## [15] "Opisthokonta-Fungi" "Archaeplastida-Chlorophyta"
## [17] "Hacrobia-Other" "Archaeplastida-Other"
## [19] "Hacrobia-Cryptophyta" "Excavata"
## [21] "Amoebozoa" "Apusozoa"
## [23] "Rhizaria-Other"
## [1] "Shallow seawater" "Venti Latte Vent" "Candelabra Vent"
## [4] "SirVentsAlot Vent" "Deep seawater" "Near vent BW"
## [7] "Candelabra Plume" "Mt Edwards Plume" "Mt Edwards Vent"
## [10] "Lab blank"
Now sum ASV counts by curated taxonomic level. Below generates both summed sequences from samples averages across replicates and for samples with replicates.
# Sum averaged counts at curated taxa level
gr_counts_avg_TAXA <- gr_counts_avg_wtax %>%
# Remove control samples & bsw with too few sequences
filter(!(Sampletype == "Control")) %>%
filter(!(LOCATION_SPECIFIC == "BSW020")) %>%
# sum by like taxa
group_by(SAMPLEID, Sampletype, LocationName, Taxa) %>%
summarise(SUM = sum(COUNT_AVG)) %>%
unite(SAMPLE, LocationName, Sampletype, SAMPLEID, sep = " ", remove = FALSE) %>%
data.frame
# View(gr_counts_avg_TAXA)
# head(gr_counts_avg_TAXA)
# head(gr_counts_filter)
# unique(gr_counts_filter$SAMPLEID)
# unique(gr_counts_filter$LOCATION_SPECIFIC)
# unique(gr_counts_filter$LocationName)
# Sum each replicate separately to curated taxa level
gr_counts_wreps_TAXA <- gr_counts_filter %>%
mutate(LocationName = case_when(
LOCATION_SPECIFIC == "Plume036" ~ "Candelabra Plume",
LOCATION_SPECIFIC == "Plume096" ~ "Mt Edwards Plume",
TRUE ~ as.character(LocationName)
)) %>%
# Remove control samples & bsw with too few sequences
filter(!(Sampletype == "Control")) %>%
filter(!(LOCATION_SPECIFIC == "BSW020")) %>%
# sum by like taxa
group_by(SAMPLEID, Sampletype, LocationName, LOCATION_SPECIFIC, Taxa) %>%
summarise(SUM = sum(COUNT)) %>%
mutate(locationspecific_mod = case_when(
LOCATION_SPECIFIC == "Plume001" ~ "NearVent001",
TRUE ~ as.character(LOCATION_SPECIFIC)
)) %>%
unite(SAMPLE, LocationName, Sampletype, SAMPLEID, sep = " ", remove = FALSE) %>%
unite(SAMPLE_REPS, LocationName, Sampletype, SAMPLEID, locationspecific_mod, sep = " ", remove = FALSE) %>%
data.frame
# unique(gr_counts_wreps_TAXA$SAMPLE_REPS)sample_order_all<-c("Shallow seawater in situ sterivex","Deep seawater in situ sterivex", "Near vent BW in situ sterivex","Near vent BW Grazing T0","Near vent BW Grazing T24","Near vent BW Grazing T36","Mt Edwards Plume in situ sterivex","Mt Edwards Vent in situ SUPR","Mt Edwards Vent Grazing T0","Mt Edwards Vent Grazing T36","Venti Latte Vent in situ SUPR","Venti Latte Vent Grazing T0","Venti Latte Vent Grazing T36","Candelabra Plume in situ sterivex","Candelabra Vent in situ SUPR","Candelabra Vent Grazing T24","SirVentsAlot Vent in situ SUPR","SirVentsAlot Vent Grazing T24")
supp_table_seq <- gr_counts_avg_TAXA %>%
select(SAMPLE, Taxa, SUM) %>%
pivot_wider(names_from = SAMPLE, values_from = SUM, values_fill = 0) %>%
arrange(Taxa) %>%
select(Taxa, sample_order_all)## Note: Using an external vector in selections is ambiguous.
## ℹ Use `all_of(sample_order_all)` instead of `sample_order_all` to silence this message.
## ℹ See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
## This message is displayed once per session.
# View(supp_table_seq)
# write_delim(supp_table_seq, path = "Suppl-18s-seq-total.txt", delim = "\t")
#
# head(gr_counts_avg_wtax)
supp_table_ASV <- gr_counts_avg_wtax %>%
# Remove control samples
filter(!(Sampletype == "Control")) %>%
# total ASVs by like taxa
group_by(SAMPLEID, Sampletype, LocationName, Taxa) %>%
summarise(ASV_total = n_distinct(Feature.ID)) %>%
unite(SAMPLE, LocationName, Sampletype, SAMPLEID, sep = " ", remove = TRUE) %>%
pivot_wider(names_from = SAMPLE, values_from = ASV_total, values_fill = 0) %>%
arrange(Taxa) %>%
select(Taxa, sample_order_all)## `summarise()` regrouping output by 'SAMPLEID', 'Sampletype', 'LocationName' (override with `.groups` argument)
# unique(gr_counts_avg_TAXA$Taxa)
level2ORDER <- c("Alveolata-Ciliates","Alveolata-Dinoflagellates","Alveolata-Syndiniales","Alveolata-Other","Rhizaria-Cercozoa","Rhizaria-Radiolaria","Rhizaria-Other","Stramenopiles-MAST","Stramenopiles-Ochrophyta","Stramenopiles-Bicoecea","Stramenopiles-Other","Hacrobia-Cryptophyta","Hacrobia-Haptophyta","Hacrobia-Other","Amoebozoa","Excavata","Apusozoa","Archaeplastida-Chlorophyta","Archaeplastida-Other","Opisthokonta-Fungi","Opisthokonta-Metazoa","Opisthokonta-Other","Unassigned-Eukaryote")
level2color <- c("#f1eef6","#d7b5d8","#df65b0","#ce1256","#fc9272","#ef3b2c","#800026","#fff7bc","#fec44f","#d95f0e","#a63603","#74c476","#238b45","#00441b","#7fcdbb","#084081","#c6dbef","#2b8cbe","#016c59","#bcbddc","#807dba","#54278f","#bdbdbd", "black")
gr_counts_avg_TAXA$LEVEL2ORDER <- factor(gr_counts_avg_TAXA$Taxa, levels=level2ORDER)
names(level2color)<-level2ORDER
sample_order_all<-c("Shallow seawater in situ sterivex","Deep seawater in situ sterivex", "Near vent BW in situ sterivex","Near vent BW Grazing T0","Near vent BW Grazing T24","Near vent BW Grazing T36","Mt Edwards Plume in situ sterivex","Mt Edwards Vent in situ SUPR","Mt Edwards Vent Grazing T0","Mt Edwards Vent Grazing T36","Venti Latte Vent in situ SUPR","Venti Latte Vent Grazing T0","Venti Latte Vent Grazing T36","Candelabra Plume in situ sterivex","Candelabra Vent in situ SUPR","Candelabra Vent Grazing T24","SirVentsAlot Vent in situ SUPR","SirVentsAlot Vent Grazing T24")
sample_name_all<-c("Shallow BSW","Deep BSW","Near vent BW","Near vent BW T0","Near vent BW T23","Near vent BW T35","Mt Edwards Plume","Mt Edwards Vent","Mt Edwards Vent T0","Mt Edwards Vent T36","Venti Latte Vent","Venti Latte Vent T0","Venti Latte Vent T29","Candelabra Plume","Candelabra Vent","Candelabra Vent T26","Sir Ventsalot Vent","Sir Ventsalot Vent T24")
gr_counts_avg_TAXA$SAMPLE_ORDER <- factor(gr_counts_avg_TAXA$SAMPLE, levels = sample_order_all, labels = sample_name_all)
exporder <- c("sterivex", "SUPR", "T0", "T24", "T36")
gr_counts_avg_TAXA$SAMPLEID_ORDER <- factor(gr_counts_avg_TAXA$SAMPLEID, levels = exporder)
gr_counts_avg_TAXA$LOCATION_ORDER <- factor(gr_counts_avg_TAXA$LocationName, levels=c("Shallow seawater", "Deep seawater", "Near vent BW", "Mt Edwards Plume","Mt Edwards Vent", "Venti Latte Vent", "Candelabra Plume","Candelabra Vent", "SirVentsAlot Vent"))
# head(gr_counts_avg_TAXA)
# Factor for dataframe with replicates
gr_counts_wreps_TAXA$LEVEL2ORDER <- factor(gr_counts_wreps_TAXA$Taxa, levels=level2ORDER)
gr_counts_wreps_TAXA$SAMPLE_ORDER <- factor(gr_counts_wreps_TAXA$SAMPLE, levels = sample_order_all, labels = sample_name_all) # Factor by sample, but will plot x as sample with reps
gr_counts_wreps_TAXA$SAMPLEID_ORDER <- factor(gr_counts_wreps_TAXA$SAMPLEID, levels = exporder)
gr_counts_wreps_TAXA$LOCATION_ORDER <- factor(gr_counts_wreps_TAXA$LocationName, levels=c("Shallow seawater", "Deep seawater", "Near vent BW", "Mt Edwards Plume","Mt Edwards Vent", "Venti Latte Vent", "Candelabra Plume","Candelabra Vent", "SirVentsAlot Vent"))
# head(gr_counts_wreps_TAXA)barplot_lev2 <- function(df){
ggplot(df, aes(x=SAMPLE_ORDER, y=SUM, fill=LEVEL2ORDER)) +
geom_bar(stat="identity", position="fill", color="black") +
scale_fill_manual(values=level2color) +
scale_y_continuous(expand = c(0,0))+
theme(legend.position = "right",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
axis.text.x = element_text(angle=90, hjust=1, vjust=0.5, color = "black", size = 12),
axis.text.y = element_text(color="black", size = 12),
axis.title = element_text(color="black", size = 12),
strip.text = element_blank(),
legend.title = element_blank()) +
labs(x="", y="Relative abundance")+
facet_grid(.~LOCATION_ORDER, space = "free", scales = "free") +
guides(fill=guide_legend(ncol=1))
}
barplot_lev2_wreps <- function(df){
ggplot(df, aes(x=SAMPLE_REPS, y=SUM, fill=LEVEL2ORDER)) +
geom_bar(stat="identity", position="fill", color="black") +
scale_fill_manual(values=level2color) +
scale_y_continuous(expand = c(0,0))+
theme(legend.position = "right",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
axis.text.x = element_text(angle=90, hjust=1, vjust=0.5, color = "black", size = 12),
axis.text.y = element_text(color="black", size = 12),
axis.title = element_text(color="black", size = 12),
strip.text = element_blank(),
legend.title = element_blank()) +
labs(x="", y="Relative abundance")+
facet_grid(.~SAMPLE_ORDER, space = "free", scales = "free") +
guides(fill=guide_legend(ncol=1))
}
insitu <- c("sterivex", "SUPR")
rm <- c("Unassigned", "Opisthokonta-Other", "Opisthokonta-Fungi", "Opisthokonta-Metazoa")insitu <- c("sterivex", "SUPR")
rm <- c("Unassigned", "Opisthokonta-Other", "Opisthokonta-Fungi", "Opisthokonta-Metazoa")
nometaz_all <- barplot_lev2(filter(gr_counts_avg_TAXA, !(Taxa %in% rm)))
nometaz_allwithmetaz_all <- barplot_lev2(filter(gr_counts_avg_TAXA))
# svg("figs/SUPPLEMENTARY-GR-tax-barplot-wmetaz.svg", w = 10, h = 8)
withmetaz_allload("data-input/GordaRidge-ASVtable-avg-19-08-2020.RData")
ventnames <- read.delim("data-input/ventnames-gordaridge.txt")
library(reshape2);
library(vegan);
library(dplyr)
library(ade4);
library(compositions);
library(tidyverse)
library(purrr)
library(cluster)
library(RColorBrewer)
library(ape)
# ventnames# Remove controls, pivot wider, and make feature ID rownames
gr_nums_wide <- counts_decont %>%
filter(!(SAMPLEID == "CTRL")) %>%
filter(!(grepl("GordaRidge_BSW020", SAMPLE))) %>%
select(Feature.ID, SAMPLE, COUNT, REP) %>%
left_join(ventnames, by = c("SAMPLE" = "SAMPLENAME")) %>%
mutate(LocationName = case_when(
LOCATION_SPECIFIC == "Plume036" ~ "Candelabra Plume",
LOCATION_SPECIFIC == "Plume096" ~ "Mt Edwards Plume",
TRUE ~ as.character(LocationName)
)) %>%
unite(SAMPLE_MOD, LocationName, Sampletype, SAMPLEID, REP, sep = "-") %>%
select(Feature.ID, COUNT, SAMPLE_MOD) %>%
pivot_wider(names_from = SAMPLE_MOD, values_from = COUNT, values_fill = 0) %>%
column_to_rownames(var = "Feature.ID")# Fix column names
gr_for_dendro <- gr_nums_wide
colnames(gr_for_dendro) <- gsub(x = names(gr_for_dendro), pattern = "-", replacement = " ")
# Relative abundance
relabun <- decostand(gr_for_dendro, MARGIN = 2, method = "total")
# colSums(relabun) # Should all equal to 1
# Cluster dendrogram (average hierarchical clustering)
cluster_gr <- hclust(dist(t(relabun)), method = "average")
# ?hclust()
# ?dist()
# ?decostandlibrary(ggdendro); library(dendextend)
dendro <- as.dendrogram(cluster_gr)
gr_dendro <- dendro_data(dendro, type = "rectangle")gr_dendro_plot <- ggplot(segment(gr_dendro)) +
geom_segment(aes(x = x, y = y, xend = xend, yend = yend)) +
coord_flip() +
scale_y_reverse(expand = c(0.2, 0.5), breaks = c(0, 0.2, 0.4, 0.6, 0.8)) +
geom_text(aes(x = x, y = y, label = label, angle = 0, hjust = 0), data= label(gr_dendro)) +
theme_dendro() +
labs(y = "Dissimilarity") +
theme(axis.text.x = element_text(color = "black", size = 14),
axis.line.x = element_line(color = "#252525"),
axis.ticks.x = element_line(),
axis.title.x = element_text(color = "black", size = 14))
# svg("figs/SUPPLEMENTARY-dendrogram-wreps.svg", w = 10, h = 8)
gr_dendro_plot# # Transform data - with CLR
# # Log-ratio
log_rats<-data.frame(compositions::clr(t(gr_nums_wide)))
# log_rats
# # look at eigenvalues
pca_lr <- prcomp(log_rats)
variance_lr <- (pca_lr$sdev^2)/sum(pca_lr$sdev^2)
# head(variance_lr)
barplot(variance_lr,
main='Log-Ratio PCA Screeplot',
xlab='PC Axis',
ylab='% Variance',
cex.names=1.5,cex.axis=1.5,cex.lab=1.5,cex.main=1.5) > Based on this screeplot - 2 axis are OK, as they show 0.079 and 0.077, respectively, of the variance.
# Extract PCA points
# pca_lr$x
pca_lr_frame<-data.frame(pca_lr$x, SAMPLE=rownames(pca_lr$x))
pca_lr_frame_wNames <- pca_lr_frame %>%
rownames_to_column(var = "SAMPLENAME") %>%
separate(SAMPLENAME, c("LocationName", "Sampletype", "SampleID", "REP"), "-", remove = FALSE) %>%
unite(shape_sample, LocationName, Sampletype, sep = " ", remove = FALSE)
# unique(pca_lr_frame_wNames$LocationName)# Factor for plotting
sample_order_all <- c("Shallow seawater","Deep seawater","Near vent BW","Mt Edwards Plume","Mt Edwards Vent","Venti Latte Vent","Candelabra Plume","Candelabra Vent","SirVentsAlot Vent")
sample_label_all <- c("Shallow BSW","Deep BSW","Near vent BW","Mt. Edwards Plume","Mt. Edwards","Venti latte","Candelabra Plume","Candelabra","Sir Ventsalot")
sample_color_all <-c("#bfbbb0","#413f44","#6f88af","#61ac86","#61ac86","#711518","#dfa837","#dfa837","#ce536b")
names(sample_color_all) <- sample_label_all
shape_order <- c("Candelabra Plume in situ","Candelabra Vent Grazing","Candelabra Vent in situ","Deep seawater in situ","Mt Edwards Plume in situ","Mt Edwards Vent Grazing","Mt Edwards Vent in situ","Near vent BW Grazing","Near vent BW in situ","Shallow seawater in situ","SirVentsAlot Vent Grazing","SirVentsAlot Vent in situ","Venti Latte Vent Grazing","Venti Latte Vent in situ")
shapes <- c(24, 21, 21, 22, 24, 21, 21, 23, 23, 22, 21, 21, 21, 21)
fill_color <- c("#dfa837","white","#dfa837","#413f44","#61ac86","white","#61ac86","white","#6f88af","#bfbbb0","white","#ce536b","white","#711518")
color_color <- c("#dfa837","#dfa837","#dfa837","#413f44","#61ac86","#61ac86","#61ac86","#6f88af","#6f88af","#bfbbb0","#ce536b","#ce536b","#711518","#711518")
pca_lr_frame_wNames$SAMPLE_ORDER <- factor(pca_lr_frame_wNames$LocationName, levels = rev(sample_order_all), labels = rev(sample_label_all))
pca_lr_frame_wNames$SHAPE_ORDER <- factor(pca_lr_frame_wNames$shape_sample, levels = shape_order)pca_18s <- ggplot(pca_lr_frame_wNames,
aes(x = PC1, y = PC2,
fill = SHAPE_ORDER,
color = SHAPE_ORDER,
shape = SHAPE_ORDER)) + #Replace label=SAMPLEID.y
# geom_text_repel(size = 3,
# box.padding = unit(0.5, "lines"))+
geom_hline(yintercept = 0) + geom_vline(xintercept = 0, color = "#525252") +
geom_point(size=4, stroke = 1.5, aes(fill=SHAPE_ORDER, color = SHAPE_ORDER, shape = SHAPE_ORDER)) +
ylab(paste0('PC2 ',round(variance_lr[2]*100,2),'%')) +
xlab(paste0('PC1 ',round(variance_lr[1]*100,2),'%')) +
scale_shape_manual(values = shapes) +
scale_fill_manual(values = fill_color) +
scale_color_manual(values = color_color) +
theme_bw() +
theme(axis.text = element_text(color="black", size=12),
legend.title = element_blank())
# pca_18sTo test the hypothesis that protistan species may be enriched at vent sites compared to surrounding seawater, 18S-derived ASVs were characterized by distribution. ## Import data and classify ASVs
## Loading objects:
## gr_counts_filter
## gr_counts_wtax
## gr_counts_avg_wtax
# unique(gr_counts_avg_wtax[, c("Sampletype", "LocationName")]) #categories to consider
# unique(gr_counts_avg_wtax$LocationName)gr_wide <- gr_counts_avg_wtax %>%
type.convert(as.is = TRUE) %>%
filter(!(Sampletype == "Control")) %>%
filter(COUNT_AVG > 0) %>%
unite(sample_type, LocationName, Sampletype, sep = "_") %>%
select(Feature.ID, sample_type, COUNT_AVG) %>%
pivot_wider(names_from = sample_type, values_from = COUNT_AVG, values_fill = 0, values_fn = sum) %>%
rowwise() %>%
mutate_at(vars(Feature.ID), factor) %>%
mutate(total = sum(c_across(where(is.numeric)))) %>%
data.frame
# names(gr_wide)# Import classifications
classifcation_schema <- read.delim("data-input/vent-asv-classification.txt")
# From the purr function
any_cols <- function(gr_wide) reduce(gr_wide, `|`)
gr_classified <- gr_wide %>%
mutate(VENT_x = ifelse(any_cols(across(contains("Vent_in.situ"), ~`>`(.,0))), "vent", ""),
VENTGRAZE_x = ifelse(any_cols(across(contains("Vent_Grazing"), ~`>`(.,0))), "ventgraze", ""),
NEAR_x = ifelse(any_cols(across(contains("Near.vent.BW_in.situ"), ~`>`(.,0))), "near", ""),
NEARGRAZE_x = ifelse(any_cols(across(contains("Near.vent.BW_Grazing"), ~`>`(.,0))), "neargraze", ""),
PLUME_x = ifelse(any_cols(across(contains("Plume_in.situ"), ~`>`(.,0))), "plume", ""),
BACK_x = ifelse(any_cols(across(contains("seawater"), ~`>`(.,0))), "bsw", "")) %>%
unite(COMPILED, ends_with("_x"), sep = "", remove = FALSE) %>%
left_join(classifcation_schema) %>%
mutate(CLASS_COMPLEX = case_when(
total == 1 ~ "Unique",
TRUE ~ as.character(CLASS_COMPLEX)),
CLASS_SIMPLE_I = case_when(
total == 1 ~ "Unique",
TRUE ~ as.character(CLASS_SIMPLE_I)),
CLASS_SIMPLE_II = case_when(
total == 1 ~ "Unique",
TRUE ~ as.character(CLASS_SIMPLE_II))) %>%
mutate(sirvents_graze = case_when(
(SirVentsAlot.Vent_Grazing > 0 & SirVentsAlot.Vent_in.situ > 0) ~ "sirvents"),
candelabra_graze = case_when(
(Candelabra.Vent_Grazing > 0 & Candelabra.Vent_in.situ > 0) ~ "candelabra"),
edwards_graze = case_when(
(Mt.Edwards.Vent_Grazing > 0 & Mt.Edwards.Vent_in.situ > 0) ~ "edwards"),
latte_graze = case_when(
(Venti.Latte.Vent_Grazing > 0 & Venti.Latte.Vent_in.situ > 0) ~ "latte"),
near_graze = case_when(
(Near.vent.BW_Grazing > 0 & Near.vent.BW_in.situ > 0) ~ "near")) %>%
unite(COMPILED_graze, ends_with("_graze"), sep = "", remove = FALSE) %>%
select(Feature.ID, starts_with("CLASS_"), ends_with("_graze")) %>%
distinct() %>%
data.frame## Joining, by = "COMPILED"
Print report on total ASV counts that fall into each category.
gr_sorted <- left_join(gr_counts_avg_wtax, gr_classified) %>%
filter(!(Sampletype == "Control"))
# head(gr_sorted)
# Stats
total <- sum(gr_sorted$COUNT_AVG); total #1.26 million sequences## [1] 1260878
gr_sorted_summary_simpleI <- gr_sorted %>%
group_by(CLASS_SIMPLE_I) %>%
summarise(totalasv = n_distinct(Feature.ID), totalseq = sum(COUNT_AVG)) %>%
mutate(Perc_seq = 100*(totalseq/total)) %>%
data.frame
gr_sorted_summary_simpleII <- gr_sorted %>%
group_by(CLASS_SIMPLE_II) %>%
summarise(totalasv = n_distinct(Feature.ID), totalseq = sum(COUNT_AVG)) %>%
mutate(Perc_seq = 100*(totalseq/total)) %>%
data.frame
gr_sorted_summary_complex <- gr_sorted %>%
group_by(CLASS_COMPLEX) %>%
summarise(totalasv = n_distinct(Feature.ID), totalseq = sum(COUNT_AVG)) %>%
mutate(Perc_seq = 100*(totalseq/total)) %>%
data.frame
# View(gr_sorted_summary_simpleI)
# View(gr_sorted_summary_simpleII)
# View(gr_sorted_summary_complex)# head(gr_sorted)
# distribution_simple vs detailed
gr_dist <- gr_sorted %>%
select(Feature.ID, CLASS_SIMPLE_I, CLASS_SIMPLE_II) %>%
distinct() %>%
mutate(DIST_simple = case_when(
CLASS_SIMPLE_I == "Background" ~ "Other",
CLASS_SIMPLE_I == "Unique" ~ "Other",
TRUE ~ CLASS_SIMPLE_I
)) %>%
select(Feature.ID, DIST_simple, DIST_detail = CLASS_SIMPLE_II) %>%
data.frame
# Select grazing enriched samples
gr_dist_grazing <- gr_sorted %>%
select(Feature.ID, ends_with("_graze")) %>%
distinct() %>%
filter(!(COMPILED_graze == "NANANANANA")) %>%
add_column(Graze_enriched = "Enriched") %>%
data.frame
# dim(gr_dist_grazing)
# table(gr_dist_grazing$COMPILED_graze)gr_stats_wtax <- left_join(gr_counts_avg_wtax, gr_dist) %>%
filter(!(Sampletype == "Control")) %>%
data.frame
gr_wtax_dist_simple <- gr_stats_wtax %>%
group_by(Taxa, DIST_simple) %>%
summarise(totalasv = n(), totalseq = sum(COUNT_AVG)) %>%
ungroup() %>%
group_by(Taxa, DIST_simple) %>%
summarise(totalasvs = sum(totalasv),
sumseqs = sum(totalseq)) %>%
mutate(percentseq = sumseqs/sum(sumseqs)*100) %>%
pivot_wider(names_from = DIST_simple, names_glue = "{DIST_simple}_{.value}",
values_from = c(totalasvs, sumseqs, percentseq)) %>%
data.frame
# View(gr_wtax_dist_simple)
# write_delim(gr_wtax_dist_simple, path = "Distribution-ASVs-bytax.txt", delim = "\t")
gr_wtax_dist_detailed <- gr_stats_wtax %>%
group_by(Taxa, DIST_detail) %>%
summarise(totalasv = n(), totalseq = sum(COUNT_AVG)) %>%
ungroup() %>%
group_by(Taxa, DIST_detail) %>%
summarise(totalasvs = sum(totalasv),
sumseqs = sum(totalseq)) %>%
mutate(percentseq = sumseqs/sum(sumseqs)*100) %>%
pivot_wider(names_from = DIST_detail, names_glue = "{DIST_detail}_{.value}",
values_from = c(totalasvs, sumseqs, percentseq)) %>%
data.frame
# View(gr_wtax_dist_detailed)
# write_delim(gr_wtax_dist_detailed, path = "Distribution-ASVs-bytax-detailed.txt", delim = "\t")Generate bar plot that summarized sequence and ASV abundance by distribution of ASV. Simple distribution determined above mentioned in text of manuscript, more detailed outline of ASV classifications for the supplementary section.
gr_stats_wtax_toplot <- gr_stats_wtax %>%
unite(sample, LocationName, Sampletype, SAMPLEID, sep = " ", remove = FALSE) %>%
group_by(sample, LocationName, Sampletype, SAMPLEID, DIST_detail) %>%
summarise(totalasvs = n_distinct(Feature.ID),
sumseqs = sum(COUNT_AVG)) %>%
data.frame## `summarise()` regrouping output by 'sample', 'LocationName', 'Sampletype', 'SAMPLEID' (override with `.groups` argument)
sample_order_all<-c("Shallow seawater in situ sterivex","Deep seawater in situ sterivex", "Near vent BW in situ sterivex","Near vent BW Grazing T0","Near vent BW Grazing T24","Near vent BW Grazing T36","Mt Edwards Plume in situ sterivex","Mt Edwards Vent in situ SUPR","Mt Edwards Vent Grazing T0","Mt Edwards Vent Grazing T36","Venti Latte Vent in situ SUPR","Venti Latte Vent Grazing T0","Venti Latte Vent Grazing T36","Candelabra Plume in situ sterivex","Candelabra Vent in situ SUPR","Candelabra Vent Grazing T24","SirVentsAlot Vent in situ SUPR","SirVentsAlot Vent Grazing T24")
sample_name_all<-c("Shallow BSW","Deep BSW","Near vent BW","Near vent BW T0","Near vent BW T23","Near vent BW T35","Mt Edwards Plume","Mt Edwards Vent","Mt Edwards Vent T0","Mt Edwards Vent T36","Venti Latte Vent","Venti Latte Vent T0","Venti Latte Vent T29","Candelabra Plume","Candelabra Vent","Candelabra Vent T26","Sir Ventsalot Vent","Sir Ventsalot Vent T24")
location_order <- c("Shallow seawater","Deep seawater","Near vent BW","Mt Edwards Plume","Mt Edwards Vent","Venti Latte Vent","Candelabra Plume","Candelabra Vent","SirVentsAlot Vent")
location_order_name <- c("Shallow BSW","Deep BSW","Near vent BW","Mt. Edwards Plume","Mt. Edwards","Venti latte","Candelabra Plume","Candelabra","Sir Ventsalot")
gr_stats_wtax_toplot$SAMPLE_ORDER <- factor(gr_stats_wtax_toplot$sample, levels = sample_order_all, labels = sample_name_all)
exporder <- c("sterivex", "SUPR", "T0", "T24", "T36")
gr_stats_wtax_toplot$SAMPLEID_ORDER <- factor(gr_stats_wtax_toplot$SAMPLEID, levels = exporder)
location_order <- c("Shallow seawater","Deep seawater","Near vent BW","Mt Edwards Plume","Mt Edwards Vent","Venti Latte Vent","Candelabra Plume","Candelabra Vent","SirVentsAlot Vent")
location_order_name <- c("Shallow BSW","Deep BSW","Near vent BW","Mt. Edwards Plume","Mt. Edwards","Venti latte","Candelabra Plume","Candelabra","Sir Ventsalot")
gr_stats_wtax_toplot$LOCATION_ORDER <- factor(gr_stats_wtax_toplot$LocationName, levels = location_order, labels = location_order_name)# Factor for distribution
category_order <- c("Vent local","Vent local (no background, no vent)","Vent resident","Vent resident and background","Background and vent local (w vent)","Background and vent local (no vent)","Background","Other","Unique")
category_color <- c("#e31a1c","#fc4e2a","#feb24c","#ffeda0","#c7e9b4","#7fcdbb","#1d91c0","#225ea8","#0c2c84")
gr_stats_wtax_toplot$CATEGORY_ORDER <- factor(gr_stats_wtax_toplot$DIST_detail, levels = category_order)
names(category_color) <- category_ordertotalseq <- ggplot(gr_stats_wtax_toplot, aes(x=SAMPLE_ORDER, y=sumseqs, fill=CATEGORY_ORDER)) +
geom_bar(stat = "identity", color = "black", position = "fill") +
# scale_fill_brewer(palette = "Accent") +
scale_fill_manual(values = category_color) +
scale_y_continuous(expand = c(0, 0)) +
facet_grid(. ~ LOCATION_ORDER, space = "free", scales = "free")+
theme(legend.position = "right",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
axis.text.x = element_text(angle=90, hjust=1, vjust=0.5, color = "black", face="bold"),
axis.text.y = element_text(color="black", face="bold"),
strip.text = element_blank(),
strip.background = element_blank(),
legend.title = element_blank()) +
labs(x="", y="")
# totalseqtotalasv <- ggplot(gr_stats_wtax_toplot, aes(x=SAMPLE_ORDER, y= totalasvs, fill=CATEGORY_ORDER)) +
geom_bar(stat = "identity", color = "black", position = "fill") +
scale_fill_manual(values = category_color) +
scale_y_continuous(expand = c(0, 0)) +
facet_grid(. ~ LOCATION_ORDER, space = "free", scales = "free") +
theme(legend.position = "right",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
axis.text.x = element_text(angle=90, hjust=1, vjust=0.5, color = "black", face="bold"),
axis.text.y = element_text(color="black", face="bold"),
strip.text = element_blank(),
strip.background = element_blank(),
legend.title = element_blank()) +
labs(x="", y="")
# totalasv# Supplementary figure
# svg("figs/SUPPLEMENTARY-seq-asv-distribution.svg", h = 8, w = 16)
plot_grid(totalseq + labs(y="Relative sequence abundance") + theme(legend.position = "none"), totalasv + labs(y="Relative ASV abundance"),
totalseq + geom_bar(stat = "identity", color = "black", position = "stack") + labs(y = "Total sequences") + theme(legend.position = "none"),
totalasv + geom_bar(stat = "identity", color = "black", position = "stack") + labs(y = "Total ASVs"),
labels = c("a", "b", "c", "d"), axis = c("lrtb"), align = c("vh"))# save(gr_stats_wtax_toplot, gr_stats_wtax, gr_dist_grazing, gr_dist, file = "data-input/GR-countinfo-withASVdistribution.RData")
# gr_dist = all ASV classification
# gr_dist_grazing = ASVs that are found in situ and in grazing
# gr_stats_wtax = complete full table with ASV classifications
# gr_stats_wtax_tplot = summarized for making figures## Loading objects:
## gr_counts_filter
## gr_counts_wtax
## gr_counts_avg_wtax
## Loading objects:
## gr_stats_wtax_toplot
## gr_stats_wtax
## gr_dist_grazing
## gr_dist
## [1] "Rhizaria-Radiolaria" "Stramenopiles-MAST"
## [3] "Opisthokonta-Metazoa" "Alveolata-Ciliates"
## [5] "Alveolata-Syndiniales" "Stramenopiles-Ochrophyta"
## [7] "Stramenopiles-Other" "Alveolata-Dinoflagellates"
## [9] "Unassigned-Eukaryote" "Rhizaria-Cercozoa"
## [11] "Opisthokonta-Other" "Hacrobia-Haptophyta"
## [13] "Alveolata-Other" "Stramenopiles-Bicoecea"
## [15] "Archaeplastida-Chlorophyta" "Hacrobia-Other"
## [17] "Archaeplastida-Other" "Hacrobia-Cryptophyta"
## [19] "Excavata" "Opisthokonta-Fungi"
## [21] "Amoebozoa" "Apusozoa"
## [23] "Rhizaria-Other"
This is a another function for further refinement of the taxonomic assignments.
# Add Taxa2 level
expand_taxa2 <- function(df){
sumseq <- sum(df$COUNT_AVG)
# Sum asv totals
df_tmp <- df %>% group_by(Feature.ID) %>%
summarise(SUM_ASV = sum(COUNT_AVG)) %>%
mutate(RelAbun = 100*(SUM_ASV/sumseq)) %>%
filter(RelAbun > 0.01) %>%
data.frame
topASVs18s <- as.character(unique(df_tmp$Feature.ID)) #Select ASVs > 0.01% of data
df$Taxa <- as.character(df$Taxa); df$Order <- as.character(df$Order)
df$Class <- as.character(df$Class); df$Division <- as.character(df$Division)
non_ciliate <- c("Alveolata-Syndiniales", "Alveolata-Dinoflagellates", "Alveolata-Other")
order <- c("Alveolata-Syndiniales", "Alveolata-Dinoflagellates")
class <- c("Alveolata-Ciliates", "Opisthokonta-Metazoa", "Opisthokonta-Fungi", "Opisthokonta-Other", "Rhizaria-Cercozoa", "Rhizaria-Radiolaria")
df2 <- df %>%
type.convert(as.is = TRUE) %>%
mutate(Taxa2 = Taxa) %>% # Duplicate Taxa column
mutate(Taxa2 = ifelse(Taxa %in% order, Order, Taxa2),
Taxa2 = ifelse(Taxa %in% class, Class, Taxa2),
Taxa2 = ifelse(Taxa %in% "Amoebozoa", Division, Taxa2),#
Taxa2 = ifelse(Taxa %in% "Apusozoa", Division, Taxa2),#
# Curate Ciliates
Taxa2 = ifelse(Class == "Spirotrichea", paste(Class, Order, sep = "-"), Taxa2),
Taxa2 = ifelse(grepl("Spirotrichea_", Taxa2), "Spirotrichea-Other", Taxa2),
Taxa2 = ifelse(grepl("Spirotrichea-NA", Taxa2), "Spirotrichea-Other", Taxa2),
Taxa2 = ifelse(grepl("Spirotrichea-Strombidiida_", Taxa2), "Spirotrichea-Strombidiida", Taxa2),
Taxa2 = ifelse(grepl("Prostomatea_1", Taxa2), "Prostomatea", Taxa2),
Taxa2 = ifelse(grepl("CONTH_", Taxa2), "Alveolata-Ciliates", Taxa2),
Taxa2 = ifelse(grepl("CONThreeP", Taxa2), "Alveolata-Ciliates", Taxa2),
# Curate dinoflagellates and Syndiniales
Taxa2 = ifelse(grepl("Dino-Group-", Taxa2), "Syndiniales Dino-Groups (I-V)", Taxa2),
Taxa2 = ifelse(Taxa2 %in% non_ciliate, "Alveolata-Other", Taxa2),
Taxa2 = ifelse(Division == "Apicomplexa", "Apicomplexa", Taxa2),
# Curate Radiolaria
Taxa2 = ifelse(Class == "Acantharea", "Rhizaria-Acantharea", Taxa2),
# Taxa2 = ifelse(grepl("Acantharea-Group-", Taxa2), "Acantharea-Groups (I,II,VI)", Taxa2),
Taxa2 = ifelse(Class == "Polycystinea", paste(Class, Order, sep = "-"), Taxa2),
Taxa2 = ifelse(Taxa2 == "Rhizaria-Radiolaria-Other", "Rhizaria-Radiolaria", Taxa2),
Taxa2 = ifelse(Taxa2 == "Rhizaria-Cercozoa-Other", "Rhizaria-Cercozoa", Taxa2),
Taxa2 = ifelse(Taxa2 == "Endomyxa-Ascetosporea", "Endomyxa", Taxa2),
Taxa2 = ifelse(Taxa2 == "Novel-clade-10-12", "Rhizaria-Cercozoa", Taxa2),
Taxa2 = ifelse(Taxa2 == "Chlorarachniophyceae", "Rhizaria-Cercozoa", Taxa2),
Taxa2 = ifelse(Taxa2 == "Rhizaria-Other", "Rhizaria-Other", Taxa2),
# Add hacrobia resolution
Taxa2 = ifelse(Taxa2 == "Hacrobia-Other", Division, Taxa2),
# Add Excavata resolution
Taxa2 = ifelse(Taxa2 == "Excavata", Division, Taxa2),
# Curate Stramenopiles
Taxa2 = ifelse(Taxa2 == "Stramenopiles-Ochrophyta", Class, Taxa2),
Taxa2 = ifelse(Taxa2 == "Stramenopiles-MAST", "MAST", Taxa2),
Taxa2 = ifelse(grepl("MOCH-", Taxa2), "MOCH", Taxa2),
Taxa2 = ifelse(Taxa2 == "Stramenopiles-Bicoecea", Family, Taxa2),
# Archaeplastidia
Taxa2 = ifelse(Division == "Streptophyta", "Archaeplastida-Streptophyta", Taxa2),
# Curate other unknown - Move low abundance ASVs to "Other"
Taxa2 = ifelse(grepl("_X", Taxa2), Taxa, Taxa2),
Taxa2 = ifelse(is.na(Taxa2), Taxa, Taxa2),
Taxa2 = ifelse(Taxa2 == "Stramenopiles-Ochrophyta", "Stramenopiles-Other", Taxa2),
Taxa2 = ifelse(Taxa2 == "Unassigned-Eukaryote-Other", "Unassigned-Eukaryote", Taxa2),
# Fixing the designation of "Other"
Taxa2 = ifelse(Taxa2 == "Alveolata-Syndiniales", "Alveolata-Other", Taxa2),
Taxa2 = ifelse(Taxa2 == "Alveolata-Dinoflagellates", "Alveolata-Other", Taxa2),
Taxa2 = ifelse(Taxa2 == "Alveolata-Dinoflagellates", "Alveolata-Other", Taxa2),
Taxa2 = ifelse(Taxa2 == "Alveolata-Ciliates", "Ciliates-Other", Taxa2),
Taxa2 = ifelse(Taxa2 == "Alveolata-Ciliates", "Ciliates-Other", Taxa2)
) %>%
mutate(Broad_Taxa = Taxa) %>%
mutate(Broad_Taxa = ifelse(Broad_Taxa %in% non_ciliate, "Alveolata", Broad_Taxa),
Broad_Taxa = ifelse(grepl("Rhizaria", Broad_Taxa), "Rhizaria", Broad_Taxa),
Broad_Taxa = ifelse(grepl("Stramenopiles", Broad_Taxa), "Stramenopiles", Broad_Taxa),
Broad_Taxa = ifelse(grepl("Archaeplastida", Broad_Taxa), "Archaeplastida", Broad_Taxa),
Broad_Taxa = ifelse(grepl("Hacrobia", Broad_Taxa), "Hacrobia", Broad_Taxa),
Broad_Taxa = ifelse(grepl("Opisthokonta", Broad_Taxa), "Opisthokonta", Broad_Taxa)) %>%
data.frame
return(df2)
}## `summarise()` ungrouping output (override with `.groups` argument)
# Add categories & set up for plotting function
gr_tax_res <- gr_counts_avg_wtax2 %>%
left_join(gr_dist) %>%
unite(sample, LocationName, Sampletype, SAMPLEID, sep = " ", remove = FALSE) %>%
data.frame## Joining, by = c("Feature.ID", "DIST_simple", "DIST_detail")
# Make table summarizing taxa stats for each sample.
# head(gr_tax_res)
asv_seq_taxa <- gr_tax_res %>%
group_by(LocationName, Sampletype, Taxa) %>%
summarize(ASV_total = n_distinct(Feature.ID),
SEQ_sum = sum(COUNT_AVG)) %>%
unite(sample, LocationName, Sampletype, sep = "-") %>%
pivot_wider(names_from = sample, values_from = c(ASV_total, SEQ_sum), values_fill = 0) %>%
data.frame## `summarise()` regrouping output by 'LocationName', 'Sampletype' (override with `.groups` argument)
# head(asv_seq_taxa)
# dim(asv_seq_taxa)
#
asv_seq_taxa2 <- gr_tax_res %>%
group_by(LocationName, Sampletype, Taxa, Taxa2) %>%
summarize(ASV_total = n_distinct(Feature.ID),
SEQ_sum = sum(COUNT_AVG)) %>%
unite(sample, LocationName, Sampletype, sep = "-") %>%
pivot_wider(names_from = sample, values_from = c(ASV_total, SEQ_sum), values_fill = 0) %>%
data.frame## `summarise()` regrouping output by 'LocationName', 'Sampletype', 'Taxa' (override with `.groups` argument)
sample_order_all<-c("Shallow seawater in situ sterivex","Deep seawater in situ sterivex", "Near vent BW in situ sterivex","Near vent BW Grazing T0","Near vent BW Grazing T24","Near vent BW Grazing T36","Mt Edwards Plume in situ sterivex","Mt Edwards Vent in situ SUPR","Mt Edwards Vent Grazing T0","Mt Edwards Vent Grazing T36","Venti Latte Vent in situ SUPR","Venti Latte Vent Grazing T0","Venti Latte Vent Grazing T36","Candelabra Plume in situ sterivex","Candelabra Vent in situ SUPR","Candelabra Vent Grazing T24","SirVentsAlot Vent in situ SUPR","SirVentsAlot Vent Grazing T24")
sample_name_all<-c("Shallow BSW","Deep BSW","Near vent BW","Near vent BW T0","Near vent BW T23","Near vent BW T35","Mt Edwards Plume","Mt Edwards Vent","Mt Edwards Vent T0","Mt Edwards Vent T36","Venti Latte Vent","Venti Latte Vent T0","Venti Latte Vent T29","Candelabra Plume","Candelabra Vent","Candelabra Vent T26","Sir Ventsalot Vent","Sir Ventsalot Vent T24")
location_order <- c("Shallow seawater","Deep seawater","Near vent BW","Mt Edwards Plume","Mt Edwards Vent","Venti Latte Vent","Candelabra Plume","Candelabra Vent","SirVentsAlot Vent")
location_order_name <- c("Shallow BSW","Deep BSW","Near vent BW","Mt. Edwards Plume","Mt. Edwards","Venti latte","Candelabra Plume","Candelabra","Sir Ventsalot")
gr_tax_res$SAMPLE_ORDER <- factor(gr_tax_res$sample, levels = sample_order_all, labels = sample_name_all)
exporder <- c("sterivex", "SUPR", "T0", "T24", "T36")
gr_tax_res$SAMPLEID_ORDER <- factor(gr_tax_res$SAMPLEID, levels = exporder)
gr_tax_res$LOCATION_ORDER <- factor(gr_tax_res$LocationName, levels = location_order, labels = location_order_name)
# head(gr_tax_res)
prepdf_tax_dist <- function(df){
df2 <- df %>%
# filter(category_final %in% category) %>%
# average across replicates
group_by(Feature.ID, RES_COSMO = DIST_simple, SAMPLE = sample, SAMPLEID, Sampletype, LocationName, Broad_Taxa, Taxon_updated, Taxa, Taxa2) %>%
summarise(COUNT_AVG2 = mean(COUNT_AVG)) %>%
ungroup() %>%
# sum by like taxa
group_by(RES_COSMO, SAMPLE, SAMPLEID, Sampletype, LocationName, Broad_Taxa, Taxa, Taxa2) %>%
summarise(SUM = sum(COUNT_AVG2)) %>%
data.frame
df2$SAMPLENAME<-factor(df2$SAMPLE, levels = sample_order_all, labels = sample_name_all)
df2$SAMPLEID_ORDER <- factor(df2$SAMPLEID, levels = c("sterivex", "SUPR", "T0", "T24", "T36"))
df2$LOCATION_ORDER <- factor(df2$LocationName, levels=location_order)
return(df2)
}gr_tax_res_richness <- gr_tax_res %>%
# Average across replicates
group_by(Feature.ID, RES_COSMO = DIST_simple, SAMPLE = sample, SAMPLEID, Sampletype, LocationName, Broad_Taxa, Taxon_updated, Taxa2) %>%
summarise(COUNT_AVG2 = mean(COUNT_AVG)) %>%
ungroup() %>%
# Get richness for each taxonomic group
group_by(RES_COSMO, Broad_Taxa, Taxa2) %>%
summarise(RICHNESS = n_distinct(Feature.ID)) %>%
data.frame## `summarise()` regrouping output by 'Feature.ID', 'RES_COSMO', 'SAMPLE', 'SAMPLEID', 'Sampletype', 'LocationName', 'Broad_Taxa', 'Taxon_updated' (override with `.groups` argument)
## `summarise()` regrouping output by 'RES_COSMO', 'Broad_Taxa' (override with `.groups` argument)
# Explore "other categories" to ensure removal is OK!
others <- c("Ciliates-Other", "Spirotrichea-Other", "Alveolata-Other", "Rhizaria-Other", "Stramenopiles-Other", "Amoebozoa", "Apusozoa", "Hacrobia-Other", "Archaeplastida-Other")
# colnames(gr_tax_res)
# tmp <- gr_tax_res %>% filter(Taxa2 %in% others) %>% select(Kingdom:Taxa, Taxa2) %>% distinct()
# View(tmp)
# hist(tmp$COUNT_AVG)gr_relAbun_toheat <- gr_tax_res_toplot %>%
filter(!(Sampletype == "Control")) %>%
# filter(Taxa %in% "Alveolata-Ciliates") %>%
# filter(!(RES_COSMO == "Other")) %>%
#Determine relative abundance within samples
group_by(Broad_Taxa, SAMPLENAME) %>%
mutate(SUMTOTAL = sum(SUM),
RelAbun = 100*(SUM/SUMTOTAL)) %>%
# ungroup() %>%
# group_by(Taxa, SAMPLENAME) %>%
# mutate(SUMTOTAL_TAXA = sum(SUM),
# RelAbun_Taxa = 100*(SUM/SUMTOTAL_TAXA)) %>%
data.frame# Re-factor
tax2_order_all <- c("Colpodea","Heterotrichea","Karyorelictea","Litostomatea","Nassophorea","Oligohymenophorea","Phyllopharyngea","Plagiopylea","Prostomatea","Spirotrichea-Choreotrichida","Spirotrichea-Euplotia","Spirotrichea-Hypotrichia","Spirotrichea-Other","Spirotrichea-Strombidiida","Spirotrichea-Tintinnida","Ciliates-Other","Gonyaulacales","Gymnodiniales","Noctilucales","Peridiniales","Prorocentrales","Suessiales","Torodiniales","Apicomplexa","Syndiniales Dino-Groups (I-V)","Alveolata-Other","Amoebozoa","Breviatea","Lobosa","Apusomonadidae","Apusozoa","Hilomonadea","Mantamonadidea","Discoba","Metamonada","Hacrobia-Cryptophyta","Hacrobia-Haptophyta","Centroheliozoa","Katablepharidophyta","Picozoa","Telonemia","Hacrobia-Other","Archaeplastida-Chlorophyta","Archaeplastida-Streptophyta","Archaeplastida-Other","Ascomycota","Basidiomycota","Chytridiomycota","Microsporidiomycota","Opisthokonta-Fungi","Annelida","Arthropoda","Cnidaria","Craniata","Ctenophora","Echinodermata","Gastrotricha","Mollusca","Nematoda","Nemertea","Opisthokonta-Metazoa","Platyhelminthes","Porifera","Rotifera","Urochordata","Choanoflagellatea","Filasterea","Ichthyosporea","Opisthokonta-Other","Endomyxa","Filosa","Filosa-Granofilosea","Filosa-Imbricatea","Filosa-Sarcomonadea","Filosa-Thecofilosea","Rhizaria-Cercozoa","Polycystinea-Collodaria","Polycystinea-Nassellaria","Polycystinea-Spumellarida","RAD-A","RAD-B","RAD-C","Rhizaria-Acantharea","Rhizaria-Radiolaria","Rhizaria-Other","MAST","Bacillariophyta","Bolidophyceae","Chrysophyceae","Dictyochophyceae","MOCH","Pelagophyceae","Synurophyceae","Caecitellaceae", "Cafeteriaceae","Stramenopiles-Other","Unassigned-Eukaryote")
gr_relAbun_toheat$TAXA2_ORDER <- factor(gr_relAbun_toheat$Taxa2, levels = rev(tax2_order_all))
broad_taxa_order <- c("Alveolata-Ciliates","Alveolata","Rhizaria",
"Stramenopiles","Amoebozoa","Apusozoa",
"Excavata","Hacrobia","Archaeplastida",
"Opisthokonta","Unassigned-Eukaryote")
gr_relAbun_toheat$Broad_ORDER <- factor(gr_relAbun_toheat$Broad_Taxa, levels = broad_taxa_order)
broad_color <- c("#ae017e","#cb181d","#d94801",
"#fe9929","#005a32","#016450",
"#084594", "#4a1486", "#238b45",
"#252525", "#252525")
# View(unique(gr_relAbun_toheat$Taxa))
# unique(gr_relAbun_toheat$Taxa2)
others <- c("Ciliates-Other", "Spirotrichea-Other", "Alveolata-Other", "Rhizaria-Other", "Stramenopiles-Other", "Stramenopiles-Bicoecea", "Amoebozoa", "Apusozoa", "Hacrobia-Other", "Archaeplastida-Other") # Make geom tile plot
tile_tax <- ggplot(gr_relAbun_toheat, aes(x = SAMPLENAME, alpha = RelAbun,
fill = Broad_ORDER, y = TAXA2_ORDER)) +
geom_tile(color = "white") +
scale_fill_manual(values = broad_color) +
theme(legend.position = "right",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
axis.text.x = element_text(angle=90, hjust=1, vjust=0.5, color = "black", size = 8),
axis.text.y = element_text(color="black", size = 8),
strip.background = element_blank(),
strip.text.y = element_text(angle = 0, hjust = 0),
legend.title = element_blank()) +
labs(x="", y="")+
facet_grid(Broad_ORDER ~ RES_COSMO, space = "free", scales = "free")
# ?geom_tilerm <- c("Opisthokonta-Fungi", "Opisthokonta-Other", "Opisthokonta-Metazoa")
# tile_tax %+% subset(gr_relAbun_toheat, !(Taxa == "Unassigned-Eukaryote" |
# RES_COSMO == "Other" |
# Taxa %in% rm | Taxa2 %in% others))broad_taxa_order <- c("Alveolata-Ciliates","Alveolata","Rhizaria",
"Stramenopiles","Amoebozoa","Apusozoa",
"Excavata","Hacrobia","Archaeplastida",
"Opisthokonta","Unassigned-Eukaryote")
gr_tax_res_richness$Broad_ORDER <- factor(gr_tax_res_richness$Broad_Taxa, levels = broad_taxa_order)
gr_tax_res_richness$TAXA2_ORDER <- factor(gr_tax_res_richness$Taxa2, levels = rev(tax2_order_all))
rm <- c("Opisthokonta-Fungi", "Opisthokonta-Other", "Opisthokonta-Metazoa")
# bubble plot richness
richness_df <- gr_tax_res_richness %>%
filter(!(RES_COSMO == "Other")) %>%
filter(!(Taxa2 %in% rm | Taxa2 == "Unassigned-Eukaryote")) %>%
data.frame
#
richness_plot <- ggplot(richness_df, aes(x = RES_COSMO, y = TAXA2_ORDER)) +
geom_point(aes(size = RICHNESS)) +
scale_size_continuous(range = c(0.2, 4)) +
facet_grid(Broad_ORDER~RES_COSMO, space = "free", scales = "free") +
theme(legend.position = "right",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
axis.text.x = element_text(angle = 90, size = 8),
axis.text.y = element_text(size = 8),
strip.text = element_blank(),
strip.background = element_blank(),
legend.title = element_blank()) +
labs(x="", y="")
# richness_plot# tile <- get_legend(tile_tax %+% subset(gr_relAbun_toheat, !(Taxa == "Unassigned-Eukaryote" |
# RES_COSMO == "Other" |
# Taxa %in% rm)))
# rich <- get_legend(richness_plot)
# svg("figs/tile_bubble_plot.svg", w = 18, h = 9)
plot_grid(tile_tax %+% subset(gr_relAbun_toheat, !(Taxa == "Unassigned-Eukaryote" |
RES_COSMO == "Other" |
Taxa %in% rm | Taxa2 %in% others)),
richness_plot %+% subset(richness_df, !(Broad_Taxa == "Opisthokonta" |
Broad_Taxa == "Unassigned-Eukaryote" |
Taxa2 %in% others)),
ncol = 2, axis = c("tb"), align = c("hv"))# plot_grid(tile_tax %+% subset(gr_relAbun_toheat, !(Taxa == "Unassigned-Eukaryote" |
# RES_COSMO == "Other" |
# Taxa %in% rm)) + geom_tile(color = "black", fill = "black"),
# richness_plot %+% subset(richness_df, !(Broad_Taxa == "Opisthokonta" |
# Broad_Taxa == "Unassigned-Eukaryote")),
# ncol = 2, axis = c("tb"), align = c("hv"))Generate additional supplementary plots as bar plot.
# Factor
ciliate_order <- c("Heterotrichea","Karyorelictea","Litostomatea","Nassophorea","Oligohymenophorea","Phyllopharyngea","Plagiopylea","Prostomatea","Spirotrichea-Choreotrichida","Spirotrichea-Euplotia","Spirotrichea-Hypotrichia","Spirotrichea-Other","Spirotrichea-Strombidiida","Spirotrichea-Tintinnida","Ciliates-Other")
gr_tax_res_toplot$CILIATE_ORDER <- factor(gr_tax_res_toplot$Taxa2, levels = ciliate_order)
CILIATE_COLOR <- c("#ffffcc","#d9f0a3","#addd8e","#78c679","#31a354","#006837","#fde0dd","#fcc5c0","#fa9fb5","#f768a1","#dd3497","#ae017e","#7a0177","#49006a","#bdbdbd")
names(CILIATE_COLOR)<-ciliate_order
# head(gr_tax_res_toplot)
ciliate_plot <- gr_tax_res_toplot %>%
filter(Taxa %in% "Alveolata-Ciliates") %>%
filter(!(RES_COSMO == "Other")) %>%
ggplot(aes(x = SAMPLENAME, y = SUM, fill = CILIATE_ORDER)) +
geom_bar(stat = "identity", position = "fill", color = "black") +
scale_fill_manual(values = CILIATE_COLOR) +
scale_y_continuous(expand = c(0,0))+
theme(legend.position = "right",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
axis.text.x = element_text(angle=90, hjust=1, vjust=0.5, color = "black", face="bold", size = 12),
axis.text.y = element_text(color="black", face="bold", size = 12),
strip.text.x = element_blank(),
strip.background = element_blank(),
legend.title = element_blank()) +
labs(x="", y="Relative abundance")+
facet_grid(RES_COSMO~LOCATION_ORDER, space = "free", scales = "free")Repeat high-resolution look at protistan biogeography, but without ciliate groups.
metaz <- c("Opisthokonta-Fungi", "Opisthokonta-Other", "Opisthokonta-Metazoa")
gr_taxa2_else <- gr_tax_res_toplot %>%
filter(!(Taxa == "Alveolata-Ciliates")) %>%
filter(!(Taxa %in% metaz)) %>%
filter(!RES_COSMO == "Other") %>%
group_by(SAMPLENAME, Taxa2, RES_COSMO, LOCATION_ORDER) %>%
summarise(SUM_2 = sum(SUM)) %>%
data.frame## `summarise()` regrouping output by 'SAMPLENAME', 'Taxa2', 'RES_COSMO' (override with `.groups` argument)
# Other protistan taxa - non-cilaite
tax_order <- c("Alveolata-Other","Gymnodiniales","Peridiniales","Prorocentrales","Torodiniales","Noctilucales","Gonyaulacales","Suessiales","Apicomplexa","Syndiniales Dino-Groups (I-V)","Breviatea","Lobosa","Amoebozoa","Hilomonadea","Apusomonadidae","Mantamonadidea","Apusozoa","Archaeplastida-Chlorophyta","Archaeplastida-Other","Archaeplastida-Streptophyta","Metamonada","Discoba","Hacrobia-Cryptophyta","Hacrobia-Haptophyta","Centroheliozoa","Katablepharidophyta","Picozoa","Telonemia","Hacrobia-Other","Endomyxa","Filosa-Imbricatea","Filosa-Granofilosea","Filosa-Thecofilosea","Filosa-Sarcomonadea","Filosa","RAD-A","RAD-B","RAD-C","Polycystinea-Spumellarida","Polycystinea-Nassellaria","Polycystinea-Collodaria","Rhizaria-Acantharea","Rhizaria-Radiolaria","Rhizaria-Cercozoa","Rhizaria-Other","MAST","Bacillariophyta","Bolidophyceae","Chrysophyceae","Dictyochophyceae","MOCH","Pelagophyceae","Stramenopiles-Other","Synurophyceae","Unassigned-Eukaryote")
color_order <- c("#bdbdbd","#f7f4f9","#e7e1ef","#d4b9da","#c994c7","#df65b0","#e7298a","#ce1256","#980043","#67001f","#fcae91","#fb6a4a","#de2d26","#fc8d59","#ef6548","#d7301f","#990000","#ffffcc","#c2e699","#78c679","#238443","#005a32","#ece2f0","#a6bddb","#67a9cf","#3690c0","#02818a","#016c59","#014636","#eff3ff","#c6dbef","#9ecae1","#6baed6","#3182bd","#08519c","#edf8fb","#ccece6","#99d8c9","#66c2a4","#2ca25f","#006d2c","#9ecae1","#6baed6","#3182bd","#08519c","#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d","#525252")
gr_taxa2_else$TAXORDER <- factor(gr_taxa2_else$Taxa2, levels = tax_order)
names(color_order) <- tax_order
# tmp <- (gr_tax_res_toplot %>% filter(!(Taxa == "Alveolata-Ciliates")) %>% filter(!(Taxa %in% metaz)) %>% select(Taxa, Taxa2))
# View(unique(tmp))
gr_plot_other <- ggplot(gr_taxa2_else, aes(x = SAMPLENAME, y = SUM_2, fill = TAXORDER)) +
geom_bar(stat = "identity", position = "fill", color = "black") +
scale_fill_manual(values = color_order) +
scale_y_continuous(expand = c(0,0))+
theme(legend.position = "right",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
axis.text.x = element_text(angle=90, hjust=1, vjust=0.5, color = "black", face="bold", size = 12),
axis.text.y = element_text(color="black", face="bold", size = 12),
strip.text.x = element_blank(),
strip.background = element_blank(),
legend.title = element_blank()) +
labs(x="", y="Relative abundance")+
# guides(fill = guide_legend(ncol = 1)) +
facet_grid(RES_COSMO~LOCATION_ORDER, space = "free", scales = "free")# What are the most abundant ASVs in each of the taxa2 categories?
# head(gr_tax_res)
gr_topASV_taxa2 <- gr_tax_res %>%
select(Feature.ID, RES_COSMO = DIST_simple, Taxa, Taxa2, Taxon_updated, COUNT_AVG) %>%
group_by(Feature.ID, RES_COSMO, Taxa, Taxa2, Taxon_updated) %>%
summarise(Total = sum(COUNT_AVG)) %>%
ungroup() %>%
group_by(Taxa, Taxa2) %>%
arrange(Taxa2, desc(Total)) %>%
top_n(10, Total) %>%
data.frame
# gr_topASV_taxa2
# write_delim(gr_topASV_taxa2, path = "supptable-topASVs-taxa2.txt", delim = "\t")
# save(gr_tax_res, file = "GR-18S-ASV-list.RData")Import 16S tag-sequence results (ASV table). Import metadata, modify sample names, and conduct taxonomic curation.
# Import metadata for 16S
ventnames_16 <- read.delim("data-input/ventnames-gordaridge-16S.txt")
# View(ventnames_16)
ventnames_16_mod <- ventnames_16 %>%
mutate(location = case_when(
grepl("NA108001", SAMPLEID_16S) ~ "NearVent",
grepl("NA108036", SAMPLEID_16S) ~ "Plume",
grepl("NA108096", SAMPLEID_16S) ~ "Plume",
grepl("BSW", SAMPLE_AMY) ~ "BSW",
grepl("Vent", LocationName) ~ "Vent"),
NA_NUM = SAMPLEID_16S) %>%
mutate(NA_NUM = str_replace(NA_NUM, "NA108", "")) %>%
mutate(NA_NUM = str_replace(NA_NUM, "NA080", "")) %>%
mutate(NA_NUM = str_replace(NA_NUM, "aSTEP", "")) %>%
mutate(NA_NUM = str_replace(NA_NUM, "bSTEP", "")) %>%
mutate(NA_NUM = str_replace(NA_NUM, "STEP20200226", "")) %>%
mutate(NA_NUM = str_replace(NA_NUM, "STEP", "")) %>%
unite(NEW_SAMPLEID, location, NA_NUM, sep ="") %>%
mutate(LocationName = case_when(
grepl("NearVent", NEW_SAMPLEID) ~ "Near vent BW",
NEW_SAMPLEID == "Plume036" ~ "Candelabra Plume",
NEW_SAMPLEID == "Plume096" ~ "Mt Edwards Plume",
grepl("SirVentsAlot", LocationName) ~ "Sir Ventsalot",
TRUE ~ as.character(LocationName)
)) %>%
data.frame
# View(ventnames_16_mod)
countbac <- read.delim("data-input/CountTable-wtax-16s-plus3-2020-06-23.txt")
# Remove samples that were repeated
rm <- c("NA108003STEP", "NA108039STEP", "NA108087STEP")Report stats on 16S tag-sequence data.
tmp <- countbac %>%
select(-all_of(rm)) %>%
pivot_longer(starts_with("NA"), names_to = "SAMPLEID_16S") %>%
left_join(ventnames_16_mod) %>%
data.frame## Joining, by = "SAMPLEID_16S"
## [1] 1190997
## [1] 6532
bac_df_plot <- countbac %>%
separate(Taxon, sep = ";D_[[:digit:]]__", into = c("Domain", "Phylum", "Class", "Order", "Family", "Genus", "Species"), remove = TRUE, extra = "merge") %>% # Warnings are OK with NAs
mutate_if(is.character, str_replace_all, pattern = "D_0__", replacement = "") %>%
filter(Domain %in% "Archaea" | Domain %in% "Bacteria") %>% #Select only archaea and bacteria, removing unassigned
select(-all_of(rm)) %>% # Remove samples we are replacing
pivot_longer(starts_with("NA"), names_to = "SAMPLEID_16S") %>%
left_join(ventnames_16_mod) %>%
data.frame
# head(bac_df_plot)## [1] 1190058
## [1] 6497
bac_df_filtered <- bac_df_plot %>%
ungroup() %>%
mutate(TOTALSEQ = sum(value)) %>%
group_by(Feature.ID) %>%
summarise(SUM = sum(value),
RELABUN = SUM/TOTALSEQ) %>%
filter(RELABUN >= 0.001) %>%
add_column(KEEP = "YES") %>%
right_join(bac_df_plot) %>%
filter(KEEP == "YES") %>%
data.frame## `summarise()` regrouping output by 'Feature.ID' (override with `.groups` argument)
## Joining, by = "Feature.ID"
Here we are curating the 16S taxonomy assignments so we can get an informative look at the in situ bacteria population diversity and biogeography. Places ASVs below a user designated THRESHOLD into the “Other” category - ASVs that make up < X% of the total data set. For this work, a threshold of 0.1% was used. The other curation of taxonomic assignment was to highlight those groups known to inhabit the region or other chemosynthetic habitats.
# Add a column for updated taxonomy name
curate_16s_tax <- function(df, THRESHOLD){
# List the class and genus level designations that should be named at class level
class <- c("Alphaproteobacteria", "Deltaproteobacteria", "Gammaproteobacteria", "Nitrososphaeria", "Thermoplasmata")
genus <- c("Arcobacter","Campylobacter","Hydrogenimonas","Nitratiruptor","Nitratifractor","Sulfurovum","Sulfurimonas","Caminibacter", "Psychrilyobacter", "SUP05 cluster")
# List the appropriate taxonomic names for this whole level to be placed into "Other" category
class_other <- c("Verrucomicrobiae")
phylum_other <- c("Planctomycetes", "Poribacteria", "Cyanobacteria", "WPS-2")
order_other <- c("Synechococcales")
totalsumseq <- sum(df$value) # total number of sequences
tmp_filter <- df %>%
group_by(Feature.ID) %>%
summarise(SUM = sum(value)) %>%
mutate(RELABUN = 100*(SUM/totalsumseq)) %>%
filter(RELABUN >= THRESHOLD) %>% #User-defined relabun threshold
data.frame
keep_asvs_relabun <- as.character(unique(tmp_filter$Feature.ID))
df2 <- df %>%
mutate(Tax_update = Phylum) %>% # Default to filling new taxa level to phylum
mutate(Tax_update = ifelse(Feature.ID %in% keep_asvs_relabun, Tax_update, "Other"), # Change name to other if it falls below relative abundance Threshold
Tax_update = ifelse(Class %in% class, paste(Phylum, Class, sep = "-"), Tax_update),
Tax_update = ifelse(Order == "Methylococcales", paste(Phylum, "Methylococcales", sep = "-"), Tax_update),
Tax_update = ifelse(Order == "Oceanospirillales", paste(Phylum, "Oceanospirillales", sep = "-"), Tax_update),
Tax_update = ifelse(Order == "Thioglobaceae", paste(Phylum, "Thioglobaceae", sep = "-"), Tax_update),
Tax_update = ifelse(Family == "Nitrospinaceae", paste(Phylum, "Nitrospinaceae", sep = "-"), Tax_update),
Tax_update = ifelse(Class %in% class_other, "Other", Tax_update),
Tax_update = ifelse(Phylum %in% phylum_other, "Other", Tax_update),
Tax_update = ifelse(Order %in% order_other, "Other", Tax_update),
Tax_update = ifelse(Genus %in% genus, paste(Phylum, Genus, sep = "-"), Tax_update))
return(df2)
}Removal of known Kitome contamination.
# head(bac_df_plot) # Add updated taxa list to this dataframe
# unique(bac_df_plot$LocationName)
bac_wcuratedtax <- curate_16s_tax(bac_df_plot %>%
filter(!(Genus == "Ralstonia")), 0.1) #Will place ASVs <0.1% abundance into "Other category"## `summarise()` ungrouping output (override with `.groups` argument)
# unique(bac_wcuratedtax$Tax_update)
# length(unique(bac_wcuratedtax$Tax_update))
tax_16s <- bac_wcuratedtax %>%
select(Tax_update, Domain:Species) %>%
distinct()
# write_delim(tax_16s, path = "tax-key-16s-21-08-2020.txt", delim = "\t")# Average sequence count for ASVs across replicates (by location name)
## Save output dataframe
bac_gr_avg <- bac_wcuratedtax %>%
# Average ASV seq count across replicates
group_by(Feature.ID, LocationName, Tax_update) %>%
summarise(AVG_count = mean(value)) %>%
data.frame## `summarise()` regrouping output by 'Feature.ID', 'LocationName' (override with `.groups` argument)
# update exisiting taxonomy
bac_wcuratedtax_toplot <- bac_wcuratedtax %>%
# Average ASV seq count across replicates
group_by(Feature.ID, LocationName, Tax_update) %>%
summarise(AVG_count = mean(value)) %>%
ungroup() %>%
group_by(LocationName, Tax_update) %>%
summarise(SUM_bytax = sum(AVG_count)) %>%
data.frame
# unique(bac_wcuratedtax_toplot$LocationName)
bac_wcuratedtax_toplot$LOCATION <- factor(bac_wcuratedtax_toplot$LocationName, levels = c("Shallow seawater", "Deep seawater", "Near vent BW","Mt Edwards Plume", "Mt Edwards Vent", "Venti Latte Vent", "Sir Ventsalot", "Candelabra Plume", "Candelabra Vent", "Purple Rain Vent", "Octopus Springs Vent", "Blue Ciliate"))tax_color<-c("#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695","#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419","#bababa","#878787","#4d4d4d","#1a1a1a")
tax_order <- c("Epsilonbacteraeota-Arcobacter","Epsilonbacteraeota-Caminibacter","Epsilonbacteraeota-Campylobacter","Epsilonbacteraeota-Hydrogenimonas","Epsilonbacteraeota-Nitratifractor","Epsilonbacteraeota-Nitratiruptor","Epsilonbacteraeota-Sulfurimonas","Epsilonbacteraeota-Sulfurovum","Proteobacteria-Alphaproteobacteria","Proteobacteria-Deltaproteobacteria","Proteobacteria-Gammaproteobacteria","Proteobacteria-Methylococcales","Proteobacteria-Oceanospirillales","Proteobacteria-SUP05 cluster","Acidobacteria","Actinobacteria","Aquificae","Bacteroidetes","Chloroflexi","Thaumarchaeota-Nitrososphaeria","Euryarchaeota-Thermoplasmata","Fusobacteria-Psychrilyobacter","Marinimicrobia (SAR406 clade)","Nitrospinae-Nitrospinaceae","Other")
bac_wcuratedtax_toplot$TAX_ORDER <- factor(bac_wcuratedtax_toplot$Tax_update, levels = tax_order)
barplot_16s <- function(df){
ggplot(df, aes(x = LOCATION, y = SUM_bytax, fill = TAX_ORDER)) +
geom_bar(stat = "identity", position = "fill", color = "black") +
scale_fill_manual(values = tax_color) +
scale_y_continuous(expand = c(0,0)) +
theme(legend.position = "right",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
axis.text.x = element_text(angle = 90, hjust=1, vjust=0.5, color = "black", face="bold", size = 12),
axis.text.y = element_text(color = "black", face="bold", size = 12),
strip.text = element_blank(),
legend.title = element_blank()) +
labs(x="", y="Relative abundance") +
facet_grid(.~LOCATION, space = "free", scales = "free") +
guides(fill=guide_legend(ncol=1))
}rm_loc <- c("Purple Rain Vent", "Octopus Springs Vent", "Blue Ciliate")
# svg("16s-curated-static.svg", h=8, w=8)
barplot_16s(bac_wcuratedtax_toplot %>% filter(!(LOCATION %in% rm_loc)))# head(bac_wcuratedtax)
# Average ASV seq count across replicates
# tmp <- bac_wcuratedtax %>%
# group_by(Feature.ID, Order, Family, Genus, Species, LocationName, Tax_update) %>%
# summarise(AVG_count = mean(value)) %>%
# filter(!(LocationName %in% rm_loc)) %>%
# filter(!(LocationName == "Near vent BW")) %>%
# filter(!(grepl("Plume", LocationName))) %>%
# data.frame
#
# unique(bac_wcuratedtax$LocationName)# head(bac_wcuratedtax)
rm_loc <- c("Purple Rain Vent", "Octopus Springs Vent", "Blue Ciliate")
bac_df_num <- bac_wcuratedtax %>%
type.convert(as.is = TRUE) %>%
filter(!LocationName %in% rm_loc) %>%
unite(SAMPLENAME, LocationName, SAMPLEID, NEW_SAMPLEID,SAMPLEID_16S, sep = "-") %>%
select(Feature.ID, SAMPLENAME, value) %>%
pivot_wider(names_from = SAMPLENAME,
values_from = value,
values_fill = 0) %>%
column_to_rownames(var = "Feature.ID") %>%
as.matrix
# head(bac_df_num)library(compositions)
df_log_clr <- data.frame(clr(t(bac_df_num)))
# # Ordination - PCA
# # ?prcomp()
pca_clr <- prcomp(df_log_clr)
# # Check variance
check_variance <- (pca_clr$sdev^2)/sum(pca_clr$sdev^2)
# head(check_variance)
# # Screeplot, how many axes are appropriate?
barplot(check_variance,
main='Log-Ratio PCA Screeplot',
xlab='PC Axis',
ylab='% Variance',
cex.names=1.5,cex.axis=1.5,cex.lab=1.5,cex.main=1.5)# Convert to dataframe and parse metadata
df_pca_clr <- data.frame(pca_clr$x, SAMPLENAME = rownames(pca_clr$x))
# head(df_pca_clr)
df_pca_clr_wnames <- df_pca_clr %>%
separate(SAMPLENAME, c("LocationName", "Sampletype", "SAMPLEID", "Fastq"), sep = "-") %>%
data.frame
# head(df_pca_clr_wnames)
unique(df_pca_clr_wnames$LocationName)## [1] "Near vent BW" "Deep seawater" "Mt Edwards Vent" "Candelabra Plume"
## [5] "Venti Latte Vent" "Shallow seawater" "Candelabra Vent" "Mt Edwards Plume"
## [9] "Sir Ventsalot"
# Factor for plotting
# sample_order_all_16s <- c("Shallow seawater","Deep seawater","Plume","Near vent BW","Mt Edwards Vent","Venti Latte Vent","Candelabra Vent","Sir Ventsalot")
sample_order_all_16s <- c("Candelabra Vent","Mt Edwards Vent","Sir Ventsalot","Venti Latte Vent","Deep seawater","Shallow seawater","Near vent BW","Candelabra Plume","Mt Edwards Plume")
# sample_color_all <-c("#bfbbb0","#413f44","#7d8c55","#6f88af","#61ac86","#711518","#dfa837","#ce536b")
sample_color_all <- c("#dfa837","#61ac86","#ce536b","#711518","#413f44","#bfbbb0","#6f88af","#dfa837","#61ac86")
names(sample_color_all) <- sample_order_all_16s
shapes <- c(21, 21, 21, 21, 22, 22, 23, 24, 24)
df_pca_clr_wnames$SAMPLE_ORDER <- factor(df_pca_clr_wnames$LocationName, levels = sample_order_all_16s)# svg("PCoA-16S-wolabels.svg", h = 8, w = 8)
pca_16s <- ggplot(df_pca_clr_wnames, aes(x = PC1, y = PC2, fill = SAMPLE_ORDER, shape = SAMPLE_ORDER, color = SAMPLE_ORDER)) +
geom_point(aes(x = PC1,y = PC2, fill = SAMPLE_ORDER, shape = SAMPLE_ORDER, color = SAMPLE_ORDER), size = 4) +
scale_fill_manual(values = sample_color_all) +
scale_color_manual(values = sample_color_all) +
scale_shape_manual(values = shapes) +
ylab(paste0('PC2 ',round(check_variance[2]*100,2),'%')) +
xlab(paste0('PC1 ',round(check_variance[1]*100,2),'%')) +
ggtitle('16S - CLR PCA Ordination') +
theme_bw() +
theme(axis.text = element_text(color = "black", size = 12),
legend.title = element_blank()) +
geom_hline(yintercept = 0) + geom_vline(xintercept = 0)
# pca_16s# svg("figs/16s-panel-supplementary.svg", w=16, h=8)
plot_grid(
barplot_16s(bac_wcuratedtax_toplot %>% filter(!(LOCATION %in% rm_loc))),
pca_16s, axis = c("tblr"), align = c("hv"),
labels = c("a", "b"))# Sort and filter eukaryote ASVs to consider:
# sumseq <- sum(gr_sorted$COUNT_AVG)
# metaz <- c("Opisthokonta-Fungi", "Opisthokonta-Other", "Opisthokonta-Metazoa")
#
# euk_data_ASV <- gr_sorted %>%
# filter(Sampletype == "in situ") %>% #select only in situ samples
# select(Feature.ID, Taxon_updated, COUNT_AVG, LocationName, Taxa) %>%
# group_by(LocationName) %>%
# # Calculate relative abundance in each sample
# mutate(RelAbun = 100*(COUNT_AVG/sum(COUNT_AVG))) %>%
# filter(!Taxa == "Unassigned-Eukaryote") %>%
# filter(!Taxa %in% metaz) %>%
# select(Feature.ID, LocationName, Taxon_EUK = Taxon_updated, RelAbun, Taxa) %>%
# mutate(AXIS = case_when(
# grepl("seawater", LocationName) ~ "Background",
# TRUE ~ "Vent_plume"
# )) %>%
# pivot_wider(id_cols = c(Feature.ID, Taxa), names_from = AXIS, values_from = "RelAbun", values_fn = mean, values_fill = 0) %>%
# filter(!(Vent_plume == 0), !(Background == 0)) %>%
# mutate(Enriched = case_when(
# Vent_plume > Background ~ "yes",
# TRUE ~ "no"
# )) %>%
# data.frame
#
# length(unique(euk_data_ASV$Feature.ID))
# head(euk_data_ASV)
# table(euk_data_ASV$Enriched)
# View(euk_data_interact)Use these ASVs downstream to explore hypotheses with correlation results. Below set up 16S and 18S rRNA gene output data as phyloseq objects to import into SPIEC-EASI. Following SPIEC-EASI analysis, export as dataframe, add metadata, and process.
Format input 18S and 16S data, save for correlation analysis.
## Loading objects:
## gr_stats_wtax_toplot
## gr_stats_wtax
## gr_dist_grazing
## gr_dist
# head(gr_stats_wtax)
# load 16S data, this has been averaged across replicates
bac_wtax <- read.delim("data-input/16s-gr-data-curated-avg.txt")# unique(gr_stats_wtax$LocationName)
# unique(bac_wtax$LocationName)
rm_loc <- c("Purple Rain Vent", "Octopus Springs Vent", "Blue Ciliate")
bac_wtax_mod <- bac_wtax %>%
filter(!(LocationName %in% rm_loc)) %>%
mutate(LocationName = case_when(
LocationName == "Sir Ventsalot" ~ "SirVentsAlot Vent",
TRUE ~ as.character(LocationName)
))
# unique(gr_stats_wtax$LocationName)
# unique(bac_wtax_mod$LocationName)# Sort and filter eukaryote ASVs to consider:
sumseq <- sum(gr_stats_wtax$COUNT_AVG)
metaz <- c("Opisthokonta-Fungi", "Opisthokonta-Other", "Opisthokonta-Metazoa")
head(gr_stats_wtax)## Feature.ID SAMPLEID Sampletype LOCATION_SPECIFIC
## 1 0009645516609bda2246e1955ff9ec1d sterivex in situ BSW081
## 2 0030ad8ce44f257c42daf3673bf92197 sterivex in situ BSW081
## 3 0030ad8ce44f257c42daf3673bf92197 SUPR in situ Vent040
## 4 0030ad8ce44f257c42daf3673bf92197 SUPR in situ Vent088
## 5 0030ad8ce44f257c42daf3673bf92197 T24 Grazing Vent110
## 6 0038478be7fb4f097ce93a5e9341af2a sterivex in situ BSW056
## LocationName
## 1 Shallow seawater
## 2 Shallow seawater
## 3 Venti Latte Vent
## 4 Candelabra Vent
## 5 SirVentsAlot Vent
## 6 Deep seawater
## Taxon_updated
## 1 Eukaryota;Rhizaria;Radiolaria;Acantharea;Acantharea-Group-II;Acantharea-Group-II_X;Acantharea-Group-II_XX;Acantharea-Group-II_XX_sp.
## 2 Eukaryota;Stramenopiles;Opalozoa;MAST-3;MAST-3J;MAST-3J_X;MAST-3J_XX;MAST-3J_XX_sp.
## 3 Eukaryota;Stramenopiles;Opalozoa;MAST-3;MAST-3J;MAST-3J_X;MAST-3J_XX;MAST-3J_XX_sp.
## 4 Eukaryota;Stramenopiles;Opalozoa;MAST-3;MAST-3J;MAST-3J_X;MAST-3J_XX;MAST-3J_XX_sp.
## 5 Eukaryota;Stramenopiles;Opalozoa;MAST-3;MAST-3J;MAST-3J_X;MAST-3J_XX;MAST-3J_XX_sp.
## 6 Eukaryota;Opisthokonta;Metazoa;Cnidaria;Cnidaria_X;Hydrozoa;Aglaura;Aglaura_hemistoma
## Kingdom Supergroup Division Class Order
## 1 Eukaryota Rhizaria Radiolaria Acantharea Acantharea-Group-II
## 2 Eukaryota Stramenopiles Opalozoa MAST-3 MAST-3J
## 3 Eukaryota Stramenopiles Opalozoa MAST-3 MAST-3J
## 4 Eukaryota Stramenopiles Opalozoa MAST-3 MAST-3J
## 5 Eukaryota Stramenopiles Opalozoa MAST-3 MAST-3J
## 6 Eukaryota Opisthokonta Metazoa Cnidaria Cnidaria_X
## Family Genus Species
## 1 Acantharea-Group-II_X Acantharea-Group-II_XX Acantharea-Group-II_XX_sp.
## 2 MAST-3J_X MAST-3J_XX MAST-3J_XX_sp.
## 3 MAST-3J_X MAST-3J_XX MAST-3J_XX_sp.
## 4 MAST-3J_X MAST-3J_XX MAST-3J_XX_sp.
## 5 MAST-3J_X MAST-3J_XX MAST-3J_XX_sp.
## 6 Hydrozoa Aglaura Aglaura_hemistoma
## Taxa COUNT_AVG DIST_simple
## 1 Rhizaria-Radiolaria 80 Other
## 2 Stramenopiles-MAST 36 Cosmopolitan
## 3 Stramenopiles-MAST 12 Cosmopolitan
## 4 Stramenopiles-MAST 34 Cosmopolitan
## 5 Stramenopiles-MAST 15 Cosmopolitan
## 6 Opisthokonta-Metazoa 21 Cosmopolitan
## DIST_detail
## 1 Background
## 2 Vent resident and background
## 3 Vent resident and background
## 4 Vent resident and background
## 5 Vent resident and background
## 6 Background and vent local (w vent)
euk_data_interact <- gr_stats_wtax %>%
type.convert(as.is = TRUE) %>%
filter(Sampletype == "in situ") %>% #select only in situ samples
filter(!Taxa %in% metaz) %>%
filter(!Taxa == "Unassigned-Eukaryote") %>%
select(Feature.ID, Taxon_updated, COUNT_AVG, LocationName) %>%
group_by(Feature.ID, Taxon_updated, LocationName) %>%
summarise(COUNT_TOTAL = sum(COUNT_AVG)) %>%
ungroup() %>%
# Calculate relative abundance
mutate(RelAbun = 100*(COUNT_TOTAL/sumseq)) %>%
# Remove ASVs ahead of network analysis
group_by(Feature.ID) %>%
filter(RelAbun > 0.001) %>%
mutate(sample_appear = n_distinct(LocationName)) %>% #Calculate how many times an ASV appears
filter(sample_appear > 3) %>% #ASV must appear in at least 3 samples
filter(COUNT_TOTAL >= 50) %>% #ASV must have at least 10 sequences
add_column(domain = "euk") %>%
unite(FEATURE, domain, Feature.ID, sep = "_", remove = TRUE) %>%
select(FEATURE, LocationName, Taxon_EUK = Taxon_updated, COUNT = COUNT_TOTAL) %>%
data.frame## `summarise()` regrouping output by 'Feature.ID', 'Taxon_updated' (override with `.groups` argument)
## [1] 9028
## [1] 328
sumseq <- sum(bac_wtax_mod$AVG_count)
locations_gr <- unique(gr_stats_wtax$LocationName)
bac_data_interact <- bac_wtax_mod %>%
filter(LocationName %in% locations_gr) %>%
filter(!(Tax_update == "Other")) %>% #Remove "other"
group_by(Feature.ID, Tax_update, LocationName) %>%
summarise(COUNT_TOTAL = sum(AVG_count)) %>%
ungroup() %>%
add_column(domain = "prok") %>%
# Calculate relative abundance
mutate(RelAbun = 100*(COUNT_TOTAL/sumseq)) %>%
# Remove ASVs ahead of network analysis
group_by(Feature.ID) %>%
filter(RelAbun > 0.001) %>%
mutate(sample_appear = n_distinct(LocationName)) %>% #Calculate how many times an ASV appears
filter(sample_appear > 3) %>% #ASV must appear in at least 3 samples
filter(COUNT_TOTAL >= 50) %>% #ASV must have at least 10 sequences
unite(FEATURE, domain, Feature.ID, sep = "_", remove = TRUE) %>%
select(FEATURE, LocationName, Taxon_BAC = Tax_update, COUNT = COUNT_TOTAL) %>%
data.frame## `summarise()` regrouping output by 'Feature.ID', 'Tax_update' (override with `.groups` argument)
## [1] 3650
## [1] 117
# save(euk_data_interact, bac_data_interact, file = "data-input/Filtered-correlation-R-objects-10-11-2020.RData")euk_df <- euk_data_interact %>%
pivot_wider(names_from = LocationName, values_from = COUNT, values_fill = 0) %>%
select(order(colnames(.))) %>%
data.frame
# head(euk_df)
euk_asv <- as.matrix(select(euk_df, -Taxon_EUK) %>% column_to_rownames(var = "FEATURE"))
euk_tax <- as.matrix(select(euk_df, FEATURE, Taxon_EUK) %>% column_to_rownames(var = "FEATURE"))
# head(bac_asv); head(bac_tax)
row.names(euk_asv) <- row.names(euk_tax)
# Phyloseq import
euk_asv_table <- otu_table(euk_asv, taxa_are_rows = TRUE)
euk_tax_table <- tax_table(euk_tax)
euk_phy <- phyloseq(euk_asv_table, euk_tax_table)
euk_phy## phyloseq-class experiment-level object
## otu_table() OTU Table: [ 328 taxa and 9 samples ]
## tax_table() Taxonomy Table: [ 328 taxa by 1 taxonomic ranks ]
bac_df <- bac_data_interact %>%
pivot_wider(names_from = LocationName, values_from = COUNT, values_fill = 0) %>%
select(order(colnames(.))) %>%
data.frame
bac_asv <- as.matrix(select(bac_df, -Taxon_BAC) %>% column_to_rownames(var = "FEATURE"))
bac_tax <- as.matrix(select(bac_df, FEATURE, Taxon_BAC) %>% column_to_rownames(var = "FEATURE"))
# head(bac_asv); head(bac_tax)
row.names(bac_asv) <- row.names(bac_tax)
# Phyloseq import
bac_asv_table <- otu_table(bac_asv, taxa_are_rows = TRUE)
bac_tax_table <- tax_table(bac_tax)
bac_phy <- phyloseq(bac_asv_table, bac_tax_table)
bac_phy## phyloseq-class experiment-level object
## otu_table() OTU Table: [ 117 taxa and 7 samples ]
## tax_table() Taxonomy Table: [ 117 taxa by 1 taxonomic ranks ]
Run SpiecEasi separately and import output tables to filter significant interactions.
Below command was run on an HPC, while other commands can be run locally. Save output and bring locally below.
# library(SpiecEasi)
# ?spiec.easi
## Cross Domain approach
# se_GR <- spiec.easi(list(bac_phy, euk_phy), method = "mb",
# nlambda = 40, lambda.min.ratio = 1e-2,
# pulsar.params = list(thresh = 0.05))
## Check output
# getStability(se_GR)
# sum(getRefit(se_GR))/2
## Extract weighted matrix
# se.beta <- as.matrix(symBeta(getOptBeta(se_GR)))
# df_beta <- as.data.frame(se.beta)
## Extract adajency matrix
# adj.mat <- getRefit(se_GR)
# df_adj <- as.data.frame(as.matrix(adj.mat))
## Assign names from original dataframes
# colnames(df_beta) <- colnames(se_GR$est$data)
# colnames(df_adj) <- colnames(se_GR$est$data)
# row.names(df_adj) <- colnames(se_GR$est$data)
# row.names(df_beta) <- colnames(se_GR$est$data)
## Save output
# save(df_adj, df_beta, se_GR, file = "gr-spieceasi-output-20-08-2020.RData")Transform into dataframes to look at relationship of pairs
## Loading objects:
## df_adj
## df_beta_weighted
## Loading objects:
## se_GR
## adj.mat
## se.beta
countbac <- read.delim("data-input/CountTable-wtax-16s-plus3-2020-06-23.txt")
# colnames(countbac)
bac_data_interact_fulltax <- bac_data_interact %>%
select(FEATURE, TAX_SHORT = Taxon_BAC) %>%
separate(FEATURE, c("domain", "Feature.ID"), sep = "_", remove = FALSE) %>%
left_join(select(countbac, Feature.ID, TAX_FULL = Taxon)) %>%
select(FEATURE, TAX_FULL, TAX_SHORT) %>%
data.frame## Joining, by = "Feature.ID"
# colnames(gr_stats_wtax)
# head(gr_tax_res)
# Make taxonomy key
tax_key_se <- euk_data_interact %>%
select(FEATURE, TAX_FULL = Taxon_EUK) %>%
separate(FEATURE, c("domain", "Feature.ID"), sep = "_", remove = FALSE) %>%
left_join(select(gr_tax_res, Feature.ID, TAX_SHORT = Taxa, EUK_2 = Taxa2, EUK_DIST = DIST_simple)) %>%
select(FEATURE, TAX_FULL, TAX_SHORT, EUK_2, EUK_DIST) %>%
bind_rows(bac_data_interact_fulltax) %>%
distinct() %>%
data.frame## Joining, by = "Feature.ID"
reformat_spieceasi <- function(df_in){
interaction <- c("PROK-EUK", "EUK-PROK")
df_in %>%
rownames_to_column(var = "SIDEA") %>%
pivot_longer(cols = starts_with(c("prok", "euk")), names_to = "SIDEB") %>%
mutate(domain_a = case_when(
grepl("prok", SIDEA) ~ "PROK",
grepl("euk", SIDEA) ~ "EUK"),
domain_b = case_when(
grepl("prok", SIDEB) ~ "PROK",
grepl("euk", SIDEB) ~ "EUK")) %>%
mutate(COMBO = paste(domain_a, domain_b, sep = "-")) %>%
mutate(COMBO_TYPE = case_when(
COMBO %in% interaction ~ "cross",
TRUE ~ "same"),
SIG_ID = paste(SIDEA, SIDEB, sep ="-")) %>%
select(-starts_with("domain")) %>%
left_join(select(tax_key_se, TAX_SIDEA = TAX_FULL, everything()), by = c("SIDEA" = "FEATURE")) %>%
left_join(select(tax_key_se, TAX_SIDEB = TAX_FULL, everything()), by = c("SIDEB" = "FEATURE"), suffix = c(".A", ".B")) %>%
data.frame
}
df_adj_long <- reformat_spieceasi(df_adj)
df_beta_long <- reformat_spieceasi(df_beta_weighted)Evaluate the range of weighted outputs from SpiecEasi. Determine if a threshold can be set.
# Get list of these parameters
# Adjacency matrix - binary, where 1 = significant interaction
# Boot strapped pvalue, showing weight of each correlation
adj_sig <- df_adj_long %>%
filter(value == 1) %>%
filter(COMBO_TYPE == "cross") %>%
select(everything(), Adjacency = value) %>%
left_join(select(df_beta_long, SIG_ID, Weight = value)) %>%
data.frame## Joining, by = "SIG_ID"
## [1] 1074 15
# head(df_adj_long)
# table(df_adj_long$value)
dim(adj_sig) # 1074 significant interactions that are cross-domain## [1] 1074 15
## SIDEA SIDEB
## 1 prok_01dd6ee6ebb76ef5250378057597a969 euk_704617bd30c6df21f779ff5300baf810
## 2 prok_0606870e7caf9d39f42f23dff84c6190 euk_908baaf2bec72eafc520025ef78d0b01
## 3 prok_08932eb86e915caa9c4034ae623d0f45 euk_607390a6a39c3a2bdd7ef41282083418
## 4 prok_08932eb86e915caa9c4034ae623d0f45 euk_75b879fa0e65e7dab54ceb63b5ce5ad3
## 5 prok_08932eb86e915caa9c4034ae623d0f45 euk_a3a866756aa4943b2f4dfbf95badcab0
## 6 prok_08932eb86e915caa9c4034ae623d0f45 euk_ac8ef156389ffd84799bf78d382a0595
## Adjacency COMBO COMBO_TYPE
## 1 1 PROK-EUK cross
## 2 1 PROK-EUK cross
## 3 1 PROK-EUK cross
## 4 1 PROK-EUK cross
## 5 1 PROK-EUK cross
## 6 1 PROK-EUK cross
## SIG_ID
## 1 prok_01dd6ee6ebb76ef5250378057597a969-euk_704617bd30c6df21f779ff5300baf810
## 2 prok_0606870e7caf9d39f42f23dff84c6190-euk_908baaf2bec72eafc520025ef78d0b01
## 3 prok_08932eb86e915caa9c4034ae623d0f45-euk_607390a6a39c3a2bdd7ef41282083418
## 4 prok_08932eb86e915caa9c4034ae623d0f45-euk_75b879fa0e65e7dab54ceb63b5ce5ad3
## 5 prok_08932eb86e915caa9c4034ae623d0f45-euk_a3a866756aa4943b2f4dfbf95badcab0
## 6 prok_08932eb86e915caa9c4034ae623d0f45-euk_ac8ef156389ffd84799bf78d382a0595
## TAX_SIDEA
## 1 D_0__Bacteria;D_1__Epsilonbacteraeota;D_2__Campylobacteria;D_3__Campylobacterales;D_4__Arcobacteraceae;D_5__Arcobacter
## 2 <NA>
## 3 D_0__Bacteria;D_1__Epsilonbacteraeota;D_2__Campylobacteria;D_3__Campylobacterales;D_4__Thiovulaceae;D_5__Sulfurimonas
## 4 D_0__Bacteria;D_1__Epsilonbacteraeota;D_2__Campylobacteria;D_3__Campylobacterales;D_4__Thiovulaceae;D_5__Sulfurimonas
## 5 D_0__Bacteria;D_1__Epsilonbacteraeota;D_2__Campylobacteria;D_3__Campylobacterales;D_4__Thiovulaceae;D_5__Sulfurimonas
## 6 D_0__Bacteria;D_1__Epsilonbacteraeota;D_2__Campylobacteria;D_3__Campylobacterales;D_4__Thiovulaceae;D_5__Sulfurimonas
## TAX_SHORT.A EUK_2.A EUK_DIST.A
## 1 Epsilonbacteraeota-Arcobacter <NA> <NA>
## 2 <NA> <NA> <NA>
## 3 Epsilonbacteraeota-Sulfurimonas <NA> <NA>
## 4 Epsilonbacteraeota-Sulfurimonas <NA> <NA>
## 5 Epsilonbacteraeota-Sulfurimonas <NA> <NA>
## 6 Epsilonbacteraeota-Sulfurimonas <NA> <NA>
## TAX_SIDEB
## 1 Eukaryota;Hacrobia;Telonemia;Telonemia_X;Telonemia_XX;Telonemia-Group-2;Telonemia-Group-2_X;Telonemia-Group-2_X_sp.
## 2 Eukaryota;Alveolata;Ciliophora;Spirotrichea;Strombidiida_D;Strombidiida_D_X;Strombidiida_D_XX;Strombidiida_D_XX_sp.
## 3 Eukaryota;Alveolata;Ciliophora;Oligohymenophorea;Scuticociliatia_1;Philasterida
## 4 Eukaryota;Hacrobia;Haptophyta;Prymnesiophyceae;Prymnesiales;Chrysochromulinaceae;Chrysochromulina;Chrysochromulina_sp.
## 5 Eukaryota;Alveolata;Ciliophora;Litostomatea;Haptoria_6;Lacrymariidae
## 6 Eukaryota;Stramenopiles;Opalozoa;MAST-3;MAST-3I;MAST-3I_X;MAST-3I_XX;MAST-3I_XX_sp.
## TAX_SHORT.B EUK_2.B EUK_DIST.B Weight
## 1 Hacrobia-Other Telonemia Cosmopolitan 1.147447e-06
## 2 Alveolata-Ciliates Spirotrichea-Strombidiida Cosmopolitan -7.159271e-03
## 3 Alveolata-Ciliates Oligohymenophorea Resident 1.146349e-02
## 4 Hacrobia-Haptophyta Hacrobia-Haptophyta Cosmopolitan -2.044291e-01
## 5 Alveolata-Ciliates Litostomatea Resident 2.509552e-01
## 6 Stramenopiles-MAST MAST Resident 1.911483e-02
# Isolate the unique interactions and make a table for export
complete_list <- adj_sig %>%
filter(COMBO == "EUK-PROK") %>%
separate(SIDEA, c("sideA", "ASV_18S"), sep = "_") %>%
separate(SIDEB, c("sideB", "ASV_16S"), sep = "_") %>%
select(-COMBO, -COMBO_TYPE, -SIG_ID, TAX_18S = TAX_SIDEA, TAX_16S = TAX_SIDEB) %>%
data.frame
# head(complete_list)
# View(complete_list)
# write_delim(complete_list, path = "Complete-cross-domain-interactions.txt", delim = "\t")
# Write to visualize in cytoscape
# write.csv(complete_list, "cross-domain-gr.csv")Of the interactions between 18S- and 16S-derived data, we are interested in capturing the putative predator prey relationships
tax_sum_interact <- adj_sig %>%
filter(COMBO == "EUK-PROK") %>%
separate(SIDEA, c("domain", "ASV_18S"), sep = "_") %>%
separate(SIDEB, c("domain2", "ASV_16S"), sep = "_") %>%
select(-starts_with("domain"), -COMBO, -COMBO_TYPE, -SIG_ID, -Adjacency) %>%
unite(INTERACTION, TAX_SHORT.A, TAX_SHORT.B, sep = "_", remove = FALSE) %>%
add_column(COUNT = 1) %>%
data.frame
# View(tax_sum_interact)
length(unique(tax_sum_interact$INTERACTION)) #Total significant interactions between euk and bac## [1] 132
# How many 18S ASVs are involved? what taxonomic groups do the interactions belong to?
# head(tax_sum_interact)
unique(tax_sum_interact$TAX_SHORT.A)## [1] "Rhizaria-Radiolaria" "Hacrobia-Haptophyta"
## [3] "Alveolata-Syndiniales" "Stramenopiles-Other"
## [5] "Alveolata-Ciliates" "Alveolata-Dinoflagellates"
## [7] "Stramenopiles-MAST" "Hacrobia-Other"
## [9] "Stramenopiles-Ochrophyta" "Archaeplastida-Chlorophyta"
## [11] "Rhizaria-Cercozoa" "Hacrobia-Cryptophyta"
# Table of significant interactions
summary_sig_interactions <- tax_sum_interact %>%
select(ASV_18S, ASV_16S, TAX_SHORT.A, COUNT) %>%
# distinct() %>%
group_by(TAX_SHORT.A) %>%
summarise(UNIQUE_18S_ASVs = n_distinct(ASV_18S),
TOTAL_18S_ASVs = sum(COUNT)) %>%
data.frame## `summarise()` ungrouping output (override with `.groups` argument)
# View(summary_sig_interactions) # Included in Table 2
# Classify interactions to taxa level 2
summary_sig_interactions_2 <- tax_sum_interact %>%
select(ASV_18S, ASV_16S, TAX_SHORT.A, EUK_2.A, COUNT) %>%
# distinct() %>%
group_by(TAX_SHORT.A, EUK_2.A) %>%
summarise(UNIQUE_18S_ASVs = n_distinct(ASV_18S),
TOTAL_18S_ASVs = sum(COUNT)) %>%
data.frame## `summarise()` regrouping output by 'TAX_SHORT.A' (override with `.groups` argument)
## ASV_18S ASV_16S
## 1 01d1a4a17e3a26ee76b34b62cb0cbef8 29b36587344bb929651696c2a41e56cc
## 2 01d1a4a17e3a26ee76b34b62cb0cbef8 9023b3075fc598bad518430ee25519bc
## 3 020295103ca8304135054e04d9110899 2806f0957cc10412ad6a887f25abc970
## 4 020295103ca8304135054e04d9110899 66c28633afa706a1e8785165a4ce933e
## 5 02c7b94c00a919db1d1ef6d9d1ce810c 6e8d876077c3eae3a1f703ac2357d76c
## 6 02c7b94c00a919db1d1ef6d9d1ce810c 929cbf36f791dd363157d90871061cee
## TAX_SIDEA
## 1 Eukaryota;Rhizaria;Radiolaria;RAD-B;RAD-B_X;RAD-B-Group-I;RAD-B-Group-I_X;RAD-B-Group-I_X_sp.
## 2 Eukaryota;Rhizaria;Radiolaria;RAD-B;RAD-B_X;RAD-B-Group-I;RAD-B-Group-I_X;RAD-B-Group-I_X_sp.
## 3 Eukaryota;Rhizaria;Radiolaria;RAD-B;RAD-B_X;RAD-B-Group-I;RAD-B-Group-I_X;RAD-B-Group-I_X_sp.
## 4 Eukaryota;Rhizaria;Radiolaria;RAD-B;RAD-B_X;RAD-B-Group-I;RAD-B-Group-I_X;RAD-B-Group-I_X_sp.
## 5 Eukaryota;Rhizaria;Radiolaria;RAD-B;RAD-B_X;RAD-B-Group-I;RAD-B-Group-I_X;RAD-B-Group-I_X_sp.
## 6 Eukaryota;Rhizaria;Radiolaria;RAD-B;RAD-B_X;RAD-B-Group-I;RAD-B-Group-I_X;RAD-B-Group-I_X_sp.
## INTERACTION TAX_SHORT.A
## 1 Rhizaria-Radiolaria_NA Rhizaria-Radiolaria
## 2 Rhizaria-Radiolaria_Epsilonbacteraeota-Sulfurimonas Rhizaria-Radiolaria
## 3 Rhizaria-Radiolaria_NA Rhizaria-Radiolaria
## 4 Rhizaria-Radiolaria_Proteobacteria-SUP05 cluster Rhizaria-Radiolaria
## 5 Rhizaria-Radiolaria_Epsilonbacteraeota-Sulfurovum Rhizaria-Radiolaria
## 6 Rhizaria-Radiolaria_Proteobacteria-Gammaproteobacteria Rhizaria-Radiolaria
## EUK_2.A EUK_DIST.A
## 1 RAD-B Resident
## 2 RAD-B Resident
## 3 RAD-B Resident
## 4 RAD-B Resident
## 5 RAD-B Resident
## 6 RAD-B Resident
## TAX_SIDEB
## 1 <NA>
## 2 D_0__Bacteria;D_1__Epsilonbacteraeota;D_2__Campylobacteria;D_3__Campylobacterales;D_4__Thiovulaceae;D_5__Sulfurimonas
## 3 <NA>
## 4 D_0__Bacteria;D_1__Proteobacteria;D_2__Gammaproteobacteria;D_3__Thiomicrospirales;D_4__Thioglobaceae;D_5__SUP05 cluster
## 5 D_0__Bacteria;D_1__Epsilonbacteraeota;D_2__Campylobacteria;D_3__Campylobacterales;D_4__Sulfurovaceae;D_5__Sulfurovum
## 6 D_0__Bacteria;D_1__Proteobacteria;D_2__Gammaproteobacteria;D_3__UBA10353 marine group;D_4__uncultured organism;D_5__uncultured organism;D_6__uncultured organism
## TAX_SHORT.B EUK_2.B EUK_DIST.B Weight COUNT
## 1 <NA> <NA> <NA> 0.004163727 1
## 2 Epsilonbacteraeota-Sulfurimonas <NA> <NA> -0.139107326 1
## 3 <NA> <NA> <NA> -0.002829730 1
## 4 Proteobacteria-SUP05 cluster <NA> <NA> 0.006002560 1
## 5 Epsilonbacteraeota-Sulfurovum <NA> <NA> 0.065705183 1
## 6 Proteobacteria-Gammaproteobacteria <NA> <NA> -0.012716197 1
# Classify interactions to taxa level 2
summary_sig_interactions_16s <- tax_sum_interact %>%
select(ASV_18S, ASV_16S, TAX_SHORT.B, COUNT) %>%
# distinct() %>%
group_by(TAX_SHORT.B) %>%
summarise(UNIQUE_16S_ASVs = n_distinct(ASV_16S),
TOTAL_16S_ASVs = sum(COUNT)) %>%
data.frame## `summarise()` ungrouping output (override with `.groups` argument)
# View(summary_sig_interactions_16s)
# What is the breakdown of bacteria and archaea ASVs?
head(tax_sum_interact)## ASV_18S ASV_16S
## 1 01d1a4a17e3a26ee76b34b62cb0cbef8 29b36587344bb929651696c2a41e56cc
## 2 01d1a4a17e3a26ee76b34b62cb0cbef8 9023b3075fc598bad518430ee25519bc
## 3 020295103ca8304135054e04d9110899 2806f0957cc10412ad6a887f25abc970
## 4 020295103ca8304135054e04d9110899 66c28633afa706a1e8785165a4ce933e
## 5 02c7b94c00a919db1d1ef6d9d1ce810c 6e8d876077c3eae3a1f703ac2357d76c
## 6 02c7b94c00a919db1d1ef6d9d1ce810c 929cbf36f791dd363157d90871061cee
## TAX_SIDEA
## 1 Eukaryota;Rhizaria;Radiolaria;RAD-B;RAD-B_X;RAD-B-Group-I;RAD-B-Group-I_X;RAD-B-Group-I_X_sp.
## 2 Eukaryota;Rhizaria;Radiolaria;RAD-B;RAD-B_X;RAD-B-Group-I;RAD-B-Group-I_X;RAD-B-Group-I_X_sp.
## 3 Eukaryota;Rhizaria;Radiolaria;RAD-B;RAD-B_X;RAD-B-Group-I;RAD-B-Group-I_X;RAD-B-Group-I_X_sp.
## 4 Eukaryota;Rhizaria;Radiolaria;RAD-B;RAD-B_X;RAD-B-Group-I;RAD-B-Group-I_X;RAD-B-Group-I_X_sp.
## 5 Eukaryota;Rhizaria;Radiolaria;RAD-B;RAD-B_X;RAD-B-Group-I;RAD-B-Group-I_X;RAD-B-Group-I_X_sp.
## 6 Eukaryota;Rhizaria;Radiolaria;RAD-B;RAD-B_X;RAD-B-Group-I;RAD-B-Group-I_X;RAD-B-Group-I_X_sp.
## INTERACTION TAX_SHORT.A
## 1 Rhizaria-Radiolaria_NA Rhizaria-Radiolaria
## 2 Rhizaria-Radiolaria_Epsilonbacteraeota-Sulfurimonas Rhizaria-Radiolaria
## 3 Rhizaria-Radiolaria_NA Rhizaria-Radiolaria
## 4 Rhizaria-Radiolaria_Proteobacteria-SUP05 cluster Rhizaria-Radiolaria
## 5 Rhizaria-Radiolaria_Epsilonbacteraeota-Sulfurovum Rhizaria-Radiolaria
## 6 Rhizaria-Radiolaria_Proteobacteria-Gammaproteobacteria Rhizaria-Radiolaria
## EUK_2.A EUK_DIST.A
## 1 RAD-B Resident
## 2 RAD-B Resident
## 3 RAD-B Resident
## 4 RAD-B Resident
## 5 RAD-B Resident
## 6 RAD-B Resident
## TAX_SIDEB
## 1 <NA>
## 2 D_0__Bacteria;D_1__Epsilonbacteraeota;D_2__Campylobacteria;D_3__Campylobacterales;D_4__Thiovulaceae;D_5__Sulfurimonas
## 3 <NA>
## 4 D_0__Bacteria;D_1__Proteobacteria;D_2__Gammaproteobacteria;D_3__Thiomicrospirales;D_4__Thioglobaceae;D_5__SUP05 cluster
## 5 D_0__Bacteria;D_1__Epsilonbacteraeota;D_2__Campylobacteria;D_3__Campylobacterales;D_4__Sulfurovaceae;D_5__Sulfurovum
## 6 D_0__Bacteria;D_1__Proteobacteria;D_2__Gammaproteobacteria;D_3__UBA10353 marine group;D_4__uncultured organism;D_5__uncultured organism;D_6__uncultured organism
## TAX_SHORT.B EUK_2.B EUK_DIST.B Weight COUNT
## 1 <NA> <NA> <NA> 0.004163727 1
## 2 Epsilonbacteraeota-Sulfurimonas <NA> <NA> -0.139107326 1
## 3 <NA> <NA> <NA> -0.002829730 1
## 4 Proteobacteria-SUP05 cluster <NA> <NA> 0.006002560 1
## 5 Epsilonbacteraeota-Sulfurovum <NA> <NA> 0.065705183 1
## 6 Proteobacteria-Gammaproteobacteria <NA> <NA> -0.012716197 1
summary_int <- tax_sum_interact %>%
group_by(INTERACTION, EUK_DIST.A) %>%
summarise(TOTAL_INTERACTIONS = sum(COUNT)) %>%
data.frame## `summarise()` regrouping output by 'INTERACTION' (override with `.groups` argument)
# head(tax_sum_interact)
tax_interact_cor <- tax_sum_interact %>%
unite(EUK, TAX_SHORT.A, EUK_2.A, sep = "_", remove = TRUE) %>%
select(EUK, PROK = TAX_SHORT.B, COUNT) %>%
group_by(EUK, PROK) %>%
summarise(SUM_COUNT = sum(COUNT)) %>%
# pivot_wider(names_from = PROK, values_from = COUNT, values_fn = sum, values_fill = 0) %>%
data.frame## `summarise()` regrouping output by 'EUK' (override with `.groups` argument)
library(ggalluvial)
# head(tax_sum_interact)
putative_prey <- tax_sum_interact %>%
# filter(!(Broad_Taxa.A == "Unassigned-Eukaryote")) %>%
group_by(TAX_SHORT.A, TAX_SHORT.B, EUK_DIST.A) %>%
summarise(count_sum = sum(COUNT)) %>%
data.frame## `summarise()` regrouping output by 'TAX_SHORT.A', 'TAX_SHORT.B' (override with `.groups` argument)
level2ORDER <- c("Alveolata-Ciliates","Alveolata-Dinoflagellates","Alveolata-Syndiniales","Alveolata-Other","Rhizaria-Cercozoa","Rhizaria-Radiolaria","Rhizaria-Other","Stramenopiles-MAST","Stramenopiles-Ochrophyta","Stramenopiles-Other","Hacrobia-Cryptophyta","Hacrobia-Haptophyta","Hacrobia-Other","Amoebozoa","Excavata","Apusozoa","Archaeplastida-Chlorophyta","Archaeplastida-Other","Opisthokonta-Fungi","Opisthokonta-Metazoa","Opisthokonta-Other","Unassigned-Eukaryote")
level2color <- c("#fa9fb5","#d7b5d8","#c994c7","#ce1256","#fc9272","#ef3b2c","#800026","#fff7bc","#fec44f","#d95f0e","#74c476","#238b45","#00441b","#7fcdbb","#084081","#c6dbef","#2b8cbe","#016c59","#bcbddc","#807dba","#54278f","#bdbdbd")
# level2color <- c("#f1eef6","#d7b5d8","#df65b0","#ce1256","#fc9272","#ef3b2c","#800026","#fff7bc","#fec44f","#d95f0e","#74c476","#238b45","#00441b","#7fcdbb","#084081","#c6dbef","#2b8cbe","#016c59","#bcbddc","#807dba","#54278f","#bdbdbd")
putative_prey$LEVEL2ORDER <- factor(putative_prey$TAX_SHORT.A, levels=level2ORDER)
names(level2color)<-level2ORDER# svg("figs/18s-16s-alluvial-interaction.svg", h = 18, w = 25)
ggplot(putative_prey,
aes(axis1 = TAX_SHORT.A, axis2 = TAX_SHORT.B, y = count_sum)) +
scale_x_discrete(limits = c("TAX_SHORT.A", "TAX_SHORT.B"), expand = c(.2, .05)) +
geom_alluvium(aes(fill = LEVEL2ORDER), alpha = 1, width = 1/3) +
scale_fill_manual(values = level2color) +
facet_wrap(.~ EUK_DIST.A, scales = "free") +
geom_stratum(size = 0.5, width = 1/3, fill = "#d9d9d9", alpha = 0.7, color = "#525252") +
geom_text(stat = "stratum", aes(label = after_stat(stratum)), size = 4, hjust = 1, color = "black") +
theme_minimal() +
theme(axis.text.x = element_blank(),
legend.title = element_blank(),
axis.text.y = element_text(color = "black", size = 14),
axis.title = element_text(color = "black", size = 14)) +
labs(y = "Total Interactions", x = "", title = "18S-16S interactions")gr <- read.delim("Grazing-calc-wCarbon-results.txt")
env <- read.delim("data-input/GR-environ-SAMPLE.txt")
# head(gr)
# View(unique(gr$SAMPLE))# Join
gr_env <- gr %>%
left_join(env, by = "SAMPLE") %>%
select(SAMPLE, SampleOrigin, Vent.name, SAMPLE_ORDER, GrazingRate_hr, Prok_turnover, ugC_L_perday_morono, DEPTH, TEMP, PH, MG, SEA_PER, MICRO) %>%
pivot_longer(cols = c(GrazingRate_hr, Prok_turnover, ugC_L_perday_morono), names_to = "Grazing_variable", values_to = "grazing_value") %>%
pivot_longer(cols = c(DEPTH, TEMP, PH, MG, SEA_PER, MICRO), names_to = "Env_variable", values_to = "env_value")
# ?pivot_longer
# head(gr_env)
# colnames(gr_env)
unique(gr_env$Grazing_variable)## [1] "GrazingRate_hr" "Prok_turnover" "ugC_L_perday_morono"
library(broom)
# View(gr_env)
regression_gr_tmp <- gr_env %>%
filter(!(Env_variable == "DEPTH")) %>%
filter(!is.na(env_value)) %>%
select(SampleOrigin, Vent.name, Grazing_variable, grazing_value, Env_variable, env_value) %>%
group_by(Grazing_variable, Env_variable) %>%
nest(-Grazing_variable, -Env_variable) %>%
mutate(lm_fit = map(data, ~lm(grazing_value ~ env_value, data = .)),
tidied = map(lm_fit, tidy)) %>%
unnest(tidied) %>%
select(Grazing_variable, Env_variable, term, estimate) %>%
pivot_wider(names_from = term, values_from = estimate) %>%
select(everything(), SLOPE = env_value) %>%
data.frame## Warning: All elements of `...` must be named.
## Did you want `data = c(SampleOrigin, Vent.name, grazing_value, env_value)`?
# head(regression_gr_tmp)
regression_gr_env <- gr_env %>%
filter(!(Env_variable == "DEPTH")) %>%
filter(!is.na(env_value)) %>%
select(SampleOrigin, Vent.name, Grazing_variable, grazing_value, Env_variable, env_value) %>%
group_by(Grazing_variable, Env_variable) %>%
nest(-Grazing_variable, -Env_variable) %>%
mutate(lm_fit = map(data, ~lm(grazing_value ~ env_value, data = .)),
glanced = map(lm_fit, glance)) %>%
unnest(glanced) %>%
select(Grazing_variable, Env_variable, r.squared, adj.r.squared) %>%
right_join(regression_gr_tmp) %>%
right_join(gr_env) %>%
data.frame## Warning: All elements of `...` must be named.
## Did you want `data = c(SampleOrigin, Vent.name, grazing_value, env_value)`?
## Joining, by = c("Grazing_variable", "Env_variable")
## Joining, by = c("Grazing_variable", "Env_variable")
sampleorder <- c("Near vent BW","Mt. Edwards","Venti latte","Candelabra","Sir Ventsalot")
shapes <- c(23, 21, 21, 21, 21)
samplecolor <- c("#6f88af","#61ac86","#711518","#dfa837","#ce536b")
regression_gr_env$ENV_LABEL <- factor(regression_gr_env$Env_variable, levels = c("TEMP","MICRO", "SEA_PER", "PH", "MG"),
labels = c(expression("Temperature"^o~"C"),
bquote("Cells "~mL^-1),
bquote("Seawater~Percent"),
bquote("pH"),
bquote("Mg (mM)")))# X = GrazingRate_hr, Prok_turnover, ugC_L_perday
# Y = DEPTH, TEMP, PH, MG, SEA_PER, MICRO
# svg("figs/SUPPLEMENTARY-grazing-env-relationship.svg", h = 10, w = 10)
plot_grid(
regression_gr_env %>%
filter(!(Env_variable == "DEPTH")) %>%
filter(!(is.na(env_value))) %>%
filter(Grazing_variable == "GrazingRate_hr") %>%
ggplot(aes(x = env_value, y = grazing_value, fill = SAMPLE_ORDER)) +
geom_abline(aes(slope = SLOPE, intercept = `X.Intercept.`), color = "black", linetype = "dashed", size = 0.5) +
geom_point(color = "black", size = 4, aes(shape = SAMPLE_ORDER)) +
geom_smooth(method = lm) +
scale_fill_manual(values = samplecolor) +
scale_shape_manual(values = shapes) +
facet_wrap(. ~ ENV_LABEL + round(r.squared, 3), scales = "free", ncol = 5,
strip.position = "bottom", labeller = label_parsed) +
theme_bw() +
theme(
strip.background = element_blank(),
strip.placement = "outside",
strip.text = element_text(color = "black", size = 10),
axis.title = element_text(color = "black", size = 10),
legend.title = element_blank()) +
labs(y = bquote("Cells "~mL^-1 ~consumed ~hr^-1), x = ""),
regression_gr_env %>%
filter(!(Env_variable == "DEPTH")) %>%
filter(!(is.na(env_value))) %>%
filter(Grazing_variable == "Prok_turnover") %>%
ggplot(aes(x = env_value, y = grazing_value, fill = SAMPLE_ORDER)) +
geom_abline(aes(slope = SLOPE, intercept = `X.Intercept.`), color = "black", linetype = "dashed", size = 0.5) +
geom_point(color = "black", size = 4, aes(shape = SAMPLE_ORDER)) +
geom_smooth(method = lm) +
scale_fill_manual(values = samplecolor) +
scale_shape_manual(values = shapes) +
facet_wrap(. ~ ENV_LABEL + round(r.squared, 3), scales = "free", ncol = 5,
strip.position = "bottom", labeller = label_parsed) +
theme_bw() +
theme(
strip.background = element_blank(),
strip.placement = "outside",
strip.text = element_text(color = "black", size = 10),
axis.title = element_text(color = "black", size = 10),
legend.title = element_blank()) +
labs(y = bquote("Prokaryote Turnover %"~day^-1), x = ""),
regression_gr_env %>%
filter(!(Env_variable == "DEPTH")) %>%
filter(!(is.na(env_value))) %>%
filter(Grazing_variable == "ugC_L_perday_morono") %>%
ggplot(aes(x = env_value, y = grazing_value, fill = SAMPLE_ORDER)) +
geom_abline(aes(slope = SLOPE, intercept = `X.Intercept.`), color = "black", linetype = "dashed", size = 0.5) +
geom_point(color = "black", size = 4, aes(shape = SAMPLE_ORDER)) +
geom_smooth(method = lm) +
scale_fill_manual(values = samplecolor) +
scale_shape_manual(values = shapes) +
facet_wrap(. ~ ENV_LABEL + round(r.squared, 3), scales = "free", ncol = 5,
strip.position = "bottom", labeller = label_parsed) +
theme_bw() +
theme(
strip.background = element_blank(),
strip.placement = "outside",
strip.text = element_text(color = "black", size = 10),
axis.title = element_text(color = "black", size = 10),
legend.title = element_blank()) +
labs(y = bquote("ug C"~L^{-1}~day^{-1}), x = ""),
nrow = 3, labels = c("a", "b", "c"))## `geom_smooth()` using formula 'y ~ x'
## `geom_smooth()` using formula 'y ~ x'
## `geom_smooth()` using formula 'y ~ x'
## Loading objects:
## gr_stats_wtax_toplot
## gr_stats_wtax
## gr_dist_grazing
## gr_dist
gr_stats_wtax_wgrazing <- gr_stats_wtax %>%
left_join(gr_dist_grazing, by = "Feature.ID") %>%
filter(Graze_enriched == "Enriched")
# dim(gr_stats_wtax)
# dim(gr_stats_wtax_wgrazing)
# Focuses down to just over 1000 ASVs
length(unique(gr_stats_wtax$Feature.ID))## [1] 9028
## [1] 1031
## [1] "Deep seawater" "Shallow seawater" "Near vent BW"
## [4] "Candelabra Plume" "Mt Edwards Plume" "Venti Latte Vent"
## [7] "SirVentsAlot Vent" "Mt Edwards Vent" "Candelabra Vent"
# Function to select ASVs of interest
dfnear <- gr_stats_wtax_wgrazing %>% type.convert(as.is = TRUE) %>%
filter(near_graze == "near") %>%
filter(LocationName == "Near vent BW") %>%
filter(SAMPLEID != "T24") %>% #Remove T1, which was not used for the grazing calculations
select(Feature.ID, LocationName, SAMPLEID, Kingdom:Species, Taxa, DIST_simple, COUNT_AVG) %>%
pivot_wider(names_from = SAMPLEID, values_from = COUNT_AVG, values_fill = 0) %>%
mutate(t0 = case_when(
T0 > sterivex ~ "higher",
TRUE ~ "lower")) %>%
mutate(tf = case_when(
T36 > T0 ~ "higher",
TRUE ~ "lower"
)) %>%
# filter(DIST_simple == "Resident") %>%
# filter(tf == "higher") %>%
##CHANGE x AXIS TO NUMERICS
pivot_longer(cols = c(sterivex, T0, T36), names_to = "samples") %>%
mutate(x_num = case_when(
samples == "sterivex" ~ 1,
samples == "T0" ~ 2,
TRUE ~ 3
)) %>%
group_by(x_num, samples, LocationName, Taxa) %>%
summarise(SUM = sum(value),
RICH = n_distinct(Feature.ID)) %>%
data.frame## `summarise()` regrouping output by 'x_num', 'samples', 'LocationName' (override with `.groups` argument)
#
# unique(gr_stats_wtax_wgrazing %>% filter(latte_graze == "latte") %>%
# filter(LocationName == "Venti Latte Vent"))
# unique(gr_stats_wtax_wgrazing$SAMPLEID)
dflatte <- gr_stats_wtax_wgrazing %>% type.convert(as.is = TRUE) %>%
filter(latte_graze == "latte") %>%
filter(LocationName == "Venti Latte Vent") %>%
# filter(SAMPLEID != "T24") %>% #Remove T1, which was not used for the grazing calculations
# select(Feature.ID, LocationName, SAMPLEID, Kingdom:Species, Taxa, DIST_simple, COUNT_AVG) %>%
# Average across in situ replicates for Venti Latte
group_by(Feature.ID, LocationName, SAMPLEID, Taxon_updated, Taxa, DIST_simple, COUNT_AVG) %>%
summarise(COUNT_AVG_AVG = mean(COUNT_AVG)) %>%
pivot_wider(names_from = SAMPLEID, values_from = COUNT_AVG_AVG, values_fill = 0) %>%
mutate(t0 = case_when(
T0 > SUPR ~ "higher",
TRUE ~ "lower")) %>%
mutate(tf = case_when(
T36 > T0 ~ "higher",
TRUE ~ "lower"
)) %>%
# filter(DIST_simple == "Resident") %>%
# filter(tf == "higher") %>%
##CHANGE x AXIS TO NUMERICS
pivot_longer(cols = c(SUPR, T0, T36), names_to = "samples") %>%
mutate(x_num = case_when(
samples == "SUPR" ~ 1,
samples == "T0" ~ 2,
TRUE ~ 3
)) %>%
group_by(x_num, samples, LocationName, Taxa) %>%
summarise(SUM = sum(value),
RICH = n_distinct(Feature.ID)) %>%
data.frame## `summarise()` regrouping output by 'Feature.ID', 'LocationName', 'SAMPLEID', 'Taxon_updated', 'Taxa', 'DIST_simple' (override with `.groups` argument)
## `summarise()` regrouping output by 'x_num', 'samples', 'LocationName' (override with `.groups` argument)
# head(dflatte)
dfsir <- gr_stats_wtax_wgrazing %>% type.convert(as.is = TRUE) %>%
filter(sirvents_graze == "sirvents") %>%
filter(LocationName == "SirVentsAlot Vent") %>%
# filter(SAMPLEID != "T24") %>% #Remove T1, which was not used for the grazing calculations
# select(Feature.ID, LocationName, SAMPLEID, Kingdom:Species, Taxa, DIST_simple, COUNT_AVG) %>%
# Average across in situ replicates for Venti Latte
group_by(Feature.ID, LocationName, SAMPLEID, Taxon_updated, Taxa, DIST_simple, COUNT_AVG) %>%
summarise(COUNT_AVG_AVG = mean(COUNT_AVG)) %>%
pivot_wider(names_from = SAMPLEID, values_from = COUNT_AVG_AVG, values_fill = 0) %>%
# mutate(t0 = case_when(
# T0 > SUPR ~ "higher",
# TRUE ~ "lower")) %>%
mutate(tf = case_when(
T24 > SUPR ~ "higher",
TRUE ~ "lower"
)) %>%
# filter(DIST_simple == "Resident") %>%
# filter(tf == "higher") %>%
##CHANGE x AXIS TO NUMERICS
pivot_longer(cols = c(SUPR, T24), names_to = "samples") %>%
mutate(x_num = case_when(
samples == "SUPR" ~ 1,
samples == "T24" ~ 2,
TRUE ~ 3
)) %>%
group_by(x_num, samples, LocationName, Taxa) %>%
summarise(SUM = sum(value),
RICH = n_distinct(Feature.ID)) %>%
data.frame## `summarise()` regrouping output by 'Feature.ID', 'LocationName', 'SAMPLEID', 'Taxon_updated', 'Taxa', 'DIST_simple' (override with `.groups` argument)
## `summarise()` regrouping output by 'x_num', 'samples', 'LocationName' (override with `.groups` argument)
# head(dfsir)
# View(gr_stats_wtax_wgrazing %>%
# filter(edwards_graze == "edwards") %>%
# filter(LocationName == "Mt Edwards Vent"))
# unique(gr_stats_wtax_wgrazing$edwards_graze)
dfed <- gr_stats_wtax_wgrazing %>% type.convert(as.is = TRUE) %>%
filter(edwards_graze == "edwards") %>%
filter(LocationName == "Mt Edwards Vent") %>%
# filter(SAMPLEID != "T24") %>% #Remove T1, which was not used for the grazing calculations
# select(Feature.ID, LocationName, SAMPLEID, Kingdom:Species, Taxa, DIST_simple, COUNT_AVG) %>%
# Average across in situ replicates for Venti Latte
group_by(Feature.ID, LocationName, SAMPLEID, Taxon_updated, Taxa, DIST_simple, COUNT_AVG) %>%
summarise(COUNT_AVG_AVG = mean(COUNT_AVG)) %>%
pivot_wider(names_from = SAMPLEID, values_from = COUNT_AVG_AVG, values_fill = 0) %>%
mutate(t0 = case_when(
T0 > SUPR ~ "higher",
TRUE ~ "lower")) %>%
mutate(tf = case_when(
T36 > SUPR ~ "higher",
TRUE ~ "lower"
)) %>%
# filter(DIST_simple == "Resident") %>%
# filter(tf == "higher") %>%
##CHANGE x AXIS TO NUMERICS
pivot_longer(cols = c(SUPR, T0, T36), names_to = "samples") %>%
mutate(x_num = case_when(
samples == "SUPR" ~ 1,
samples == "T0" ~ 2,
TRUE ~ 3
)) %>%
group_by(x_num, samples, LocationName, Taxa) %>%
summarise(SUM = sum(value),
RICH = n_distinct(Feature.ID)) %>%
data.frame## `summarise()` regrouping output by 'Feature.ID', 'LocationName', 'SAMPLEID', 'Taxon_updated', 'Taxa', 'DIST_simple' (override with `.groups` argument)
## `summarise()` regrouping output by 'x_num', 'samples', 'LocationName' (override with `.groups` argument)
level2ORDER <- c("Alveolata-Ciliates","Alveolata-Dinoflagellates","Alveolata-Syndiniales","Alveolata-Other","Rhizaria-Cercozoa","Rhizaria-Radiolaria","Rhizaria-Other","Stramenopiles-MAST","Stramenopiles-Ochrophyta","Stramenopiles-Other","Hacrobia-Cryptophyta","Hacrobia-Haptophyta","Hacrobia-Other","Amoebozoa","Excavata","Apusozoa","Archaeplastida-Chlorophyta","Archaeplastida-Other","Opisthokonta-Fungi","Opisthokonta-Metazoa","Opisthokonta-Other","Unassigned-Eukaryote")
level2color <- c("#f1eef6","#d7b5d8","#df65b0","#ce1256","#fc9272","#ef3b2c","#800026","#fff7bc","#fec44f","#d95f0e","#74c476","#238b45","#00441b","#7fcdbb","#084081","#c6dbef","#2b8cbe","#016c59","#bcbddc","#807dba","#54278f","#bdbdbd")
names(level2color)<-level2ORDER
# FACTORING:
dfnear$LEVEL2ORDER <- factor(dfnear$Taxa, levels=level2ORDER)
dflatte$LEVEL2ORDER <- factor(dflatte$Taxa, levels = level2ORDER)
dfsir$LEVEL2ORDER <- factor(dfsir$Taxa, levels = level2ORDER)
dfed$LEVEL2ORDER <- factor(dfed$Taxa, levels = level2ORDER)
#
nearbw <- ggplot(dfnear, aes(x = x_num, fill = LEVEL2ORDER, y = SUM)) +
geom_area(aes(fill = LEVEL2ORDER), position = "stack", stat = "identity", color = "black") +
scale_x_discrete(expand = c(0,0)) +
scale_fill_manual(values = level2color) +
annotate(geom="text", x=1.1, y=-0.02, label="in situ",
color="black") +
annotate(geom="text", x=2, y=-0.02, label="T0",
color="black") +
annotate(geom="text", x=2.9, y=-0.02, label="TF",
color="black") +
theme(legend.position = "right",
panel.border = element_blank(),
panel.background = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_line(),
axis.text.y = element_text(color="black", face="bold"),
legend.title = element_blank()) +
labs(x="Near vent BW", y="Relative abundance")
# nearbwventi <- ggplot(dflatte, aes(x = x_num, fill = LEVEL2ORDER, y = SUM)) +
geom_area(aes(fill = LEVEL2ORDER), position = "stack", stat = "identity", color = "black") +
scale_x_discrete(expand = c(0,0)) +
scale_fill_manual(values = level2color) +
# scale_color_manual(values = level2color) +
annotate(geom="text", x=1.1, y=-0.02, label="in situ",
color="black") +
annotate(geom="text", x=2, y=-0.02, label="T0",
color="black") +
annotate(geom="text", x=2.9, y=-0.02, label="TF",
color="black") +
theme(legend.position = "right",
panel.border = element_blank(),
panel.background = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_line(),
axis.text.y = element_text(color="black", face="bold"),
legend.title = element_blank()) +
labs(x="Venti latte", y="Relative abundance")
# ventisirvent <- ggplot(dfsir, aes(x = x_num, fill = LEVEL2ORDER, y = SUM)) +
geom_area(aes(fill = LEVEL2ORDER), position = "stack", stat = "identity", color = "black") +
scale_x_discrete(expand = c(0,0)) +
scale_fill_manual(values = level2color) +
# scale_color_manual(values = level2color) +
annotate(geom="text", x=1.1, y=-0.02, label="in situ",
color="black") +
annotate(geom="text", x=2, y=-0.02, label="TF",
color="black") +
# annotate(geom="text", x=2.9, y=-0.02, label="TF",
# color="black") +
theme(legend.position = "right",
panel.border = element_blank(),
panel.background = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_line(),
axis.text.y = element_text(color="black", face="bold"),
legend.title = element_blank()) +
labs(x="Sir Ventsalot", y="Relative abundance")
# sirventedward <- ggplot(dfed, aes(x = x_num, fill = LEVEL2ORDER, y = SUM)) +
geom_area(aes(fill = LEVEL2ORDER), position = "stack", stat = "identity", color = "black") +
scale_x_discrete(expand = c(0,0)) +
scale_fill_manual(values = level2color) +
# scale_color_manual(values = level2color) +
annotate(geom="text", x=1.1, y=-0.02, label="in situ",
color="black") +
annotate(geom="text", x=2, y=-0.02, label="TF",
color="black") +
annotate(geom="text", x=2.9, y=-0.02, label="TF",
color="black") +
theme(legend.position = "right",
panel.border = element_blank(),
panel.background = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_line(),
axis.text.y = element_text(color="black", face="bold"),
legend.title = element_blank()) +
labs(x="Sir Ventsalot", y="Relative abundance")
# edward## R version 3.6.1 (2019-07-05)
## Platform: x86_64-apple-darwin13.4.0 (64-bit)
## Running under: macOS Mojave 10.14.6
##
## Matrix products: default
## BLAS/LAPACK: /Users/sarahhu/anaconda3/envs/r_3.6.0/lib/R/lib/libRblas.dylib
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] broom_0.7.0 ggalluvial_0.12.1 dendextend_1.14.0
## [4] ggdendro_0.1-20 ape_5.3 RColorBrewer_1.1-2
## [7] cluster_2.1.0 compositions_1.40-5 bayesm_3.1-4
## [10] robustbase_0.93-6 tensorA_0.36.1 ade4_1.7-15
## [13] vegan_2.5-6 lattice_0.20-41 permute_0.9-5
## [16] decontam_1.6.0 phyloseq_1.30.0 patchwork_1.0.0.9000
## [19] cowplot_1.0.0 reshape2_1.4.4 forcats_0.5.0
## [22] stringr_1.4.0 dplyr_1.0.0 purrr_0.3.4
## [25] readr_1.3.1 tidyr_1.1.0 tibble_3.0.1
## [28] ggplot2_3.3.1 tidyverse_1.3.0
##
## loaded via a namespace (and not attached):
## [1] VGAM_1.1-3 colorspace_1.4-1 ellipsis_0.3.1
## [4] XVector_0.26.0 fs_1.4.1 rstudioapi_0.11
## [7] farver_2.0.3 fansi_0.4.1 lubridate_1.7.8
## [10] xml2_1.3.2 codetools_0.2-16 splines_3.6.1
## [13] knitr_1.28 SpiecEasi_1.1.0 jsonlite_1.6.1
## [16] dbplyr_1.4.4 compiler_3.6.1 httr_1.4.1
## [19] backports_1.1.7 assertthat_0.2.1 Matrix_1.2-18
## [22] cli_2.0.2 htmltools_0.4.0 tools_3.6.1
## [25] igraph_1.2.5 gtable_0.3.0 glue_1.4.1
## [28] Rcpp_1.0.5 Biobase_2.46.0 cellranger_1.1.0
## [31] vctrs_0.3.0 Biostrings_2.54.0 multtest_2.42.0
## [34] nlme_3.1-148 iterators_1.0.12 xfun_0.14
## [37] rvest_0.3.5 lifecycle_0.2.0 DEoptimR_1.0-8
## [40] zlibbioc_1.32.0 MASS_7.3-51.6 scales_1.1.1
## [43] hms_0.5.3 parallel_3.6.1 biomformat_1.14.0
## [46] huge_1.3.4.1 rhdf5_2.30.1 yaml_2.2.1
## [49] gridExtra_2.3 stringi_1.4.6 S4Vectors_0.24.4
## [52] foreach_1.5.0 BiocGenerics_0.32.0 shape_1.4.4
## [55] rlang_0.4.6 pkgconfig_2.0.3 evaluate_0.14
## [58] Rhdf5lib_1.8.0 labeling_0.3 tidyselect_1.1.0
## [61] plyr_1.8.6 magrittr_1.5 R6_2.4.1
## [64] IRanges_2.20.2 generics_0.0.2 DBI_1.1.0
## [67] pillar_1.4.4 haven_2.3.1 withr_2.2.0
## [70] mgcv_1.8-31 survival_3.1-12 pulsar_0.3.7
## [73] modelr_0.1.8 crayon_1.3.4 rmarkdown_2.2
## [76] viridis_0.5.1 grid_3.6.1 readxl_1.3.1
## [79] data.table_1.12.8 blob_1.2.1 reprex_0.3.0
## [82] digest_0.6.25 stats4_3.6.1 munsell_0.5.0
## [85] glmnet_4.0-2 viridisLite_0.3.0